How to display theme's .tpl in module (in hook)? - module

I am making a module, that suposed to use templates from my custom theme.
The problem is that I don't understand the function Module::display(), it gets two arguments "file" and "template", what is the file? What is it for?
If I do this:
public function hookDisplayHome{
return $this->display(__FILE__, '../../templates/my_custom_theme/mb_templates/aboutus.tpl');
}
It displays error "Not found template file" in module "my_module". Of course if I change the template path to one of the templates of my module, then it works. But I need to access theme's template, not my module's.
With this I have also another additional question. Is there any documentation on Prestashop's functions? I really tried to analyse the function $this -> display() but couldn't find any place where is described what are the arguments of this function etc. There is Prestashop documentation https://devdocs.prestashop.com but it is very general, and has no description of the functions.
I've checked the class Module.php, the function has no comments :(
What is the official way when you want to check what the function does, returns, and what parameters accepts? It has to be somewhere, right?

So for those who also struggle with this problem, based on this answer https://stackoverflow.com/a/53576139/2796533
The easiest solution seems to be using module's template in $this -> display() and then in that template include the theme's template:
{include file='../../../themes/my_custom_theme/mb_templates/aboutus.tpl'}

Related

What is the hook for the list of products?

I need a hook that I can't find in the documentation, but logically it should exist.
In my module, I need to add some html in category page (or search results page) after the tile with the products but before pagination.
Which hook is best to use?
There is no default hook for your goal, but you can create your own one and use it within your module. The inconvenience is that you will be able to use it only in modified themes or you will need to add it manually to all new ones. To create the desirable hook you need to put
{hook h='displayYourHook' info=$someData}
in the top of your_theme/templates/catalog/_partials/products-top.tpl
and then just use it like a default hook within your module
public function hookDisplayYourHook($params)
{
// $params can be some information. ID of category for example
do all necessary stuff here
}
and also do not forget to register your hook during the module installation
public function install()
{
....
&& $this->registerHook('addproduct')
....
}
Also, I presume that you use prestashop 1.7.* if not - some code can be different

Vue JSX bind to class name

I'm building a simple TodoMVC app using Vue + JSX, but the documentation seems to be seriously lacking. Thus, I'm writing down the points I need to address as part of a CR to the appropriate projects. The only document I've read as of yet is the guide, which doesn't cover much JSX at all. I don't know much about how the framework works yet, but I sure prefer using the render method over the string templates for performance/network reasons.
question
What's the proper way to create a class name binding in Vue + JSX? In my TodoItem component, creating either a class or className attribute makes Babel throw a compile error complaining the API is deprecated (and suggesting I add several seemingly unrelated dependencies to the mix). Plus, including the class property in the data object seems to change nothing.
secondary question
The lack of documentation, plus the wording on the guide gives the impression JSX is not the "proper" way to write Vue components. Is that so? What's the idiomatic way to do it, given I don't want to ship the compiler along with my app?
links
code on codepan
I sure prefer using the render method over the string templates for performance/network reasons.
If you're writing *.vue files and bundling them with vue-loader (Webpack), the HTML template gets compiled into a JavaScript render function anyway, so there isn't really any kind of performance issues in that sense.
On the other hand, if you're writing your Vue components with string templates like this:
new Vue({
template: '<div>Hello</div>'
})
then you'll need the Vue template compiler at runtime to convert the string into a render function.
Typically people would opt for writing render functions manually if they need to do something specific that would be difficult/impossible to do with the HTML template alone.
You've probably already read the docs, but just in case, the relevant sections are:
Render Functions & JSX
The Data Object In-Depth
babel-plugin-transform-vue-jsx Usage
What's the proper way to create a class name binding in Vue + JSX?
You would just bind to the class attribute like you would any other attribute:
<div class={this.klass}>
data() {
return {
klass: 'foo'
}
}
The lack of documentation, plus the wording on the guide gives the impression JSX is not the "proper" way to write Vue components. Is that so? What's the idiomatic way to do it, given I don't want to ship the compiler along with my app?
JSX is definitely supported, but it is not the recommended approach. The recommended approach is to write *.vue files and load them with vue-loader (if using Webpack).
Vue comes in two versions, one with and one without the template compiler. The one with the compiler included is only for development and should not be used for production builds (unless you require string template to render function compilation at runtime, which is unlikely). See Explanation of Build Files for more info.
Typically you write HTML string templates, and they get compiled to render functions (by vue-loader) at build time.

Prestashop Quick search block hook

i have very strange problem with latest version of prestashop installed when i unhook quick search block from displayTOP then slider and products got disturbed on page then i have to disable Quick search block from modules after that it works fine.
actually i want to display Quick search block separately on top using header.tpl file with
method
{include file=$tpl_dir./modules/blocksearch/blocksearch-top.tpl}
kindly help me to resolve this issue i'm customizing the default-bootstrap theme and using prestashop 1.6.0.9
Regards
You may create a custom hook and attache the module quick search block to this hook and in the tpl call your new hook where you want like ! {HOOK_YOURHOOK}
in your module :
public function hookDisplayQuickSearch($params)
{
$this->hookTop($params)
}
in header.tpl add
{HOOK_DISPLAYQUICKSEARCH}
Notice : i didn't try the code

Extend products with custom module in Prestashop

I am writing a module, I know how to build a global module, but I would like to do the following:
Have global properties (already covered)
Have the same properties in a tab in the products interface in the admin where the user can override the global properties (still to do)
Now my question:
How do I add an additional tab to the products interface in the prestashop admin?
I guess I can easily call these in my module templates and check if global is overridden?
Thanks for the feedback,
Eric
PS. Using prestashop 1.5.8, will worry later to extend to 1.6
To add an additional tab to product edit page, you can use hookDisplayAdminProductsExtra.
First, you will have to register this hook inside install() method:
public function install() {
...
$this->registerHook('displayAdminProductsExtra')...
...
}
after that you define this:
public function hookDisplayAdminProductsExtra($params) {
...
return $this->display(__FILE__, 'views/admin/yourtemplatefile.tpl');
}
File yourtemplatefile.tpl defines the contents of your extra tab. Extra variables used in this file can be assigned inside hookDisplayAdminProductsExtra function
Here you can find additional information about creating a module:
http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module
And here you can find information about hooks:
http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5

Prestashop - override function in existing prestashop module

I would like to change existing prestashop module without copying it and creating new one. I know that it is possible to override .tpl files in prestashop, but is it possible to do same thing with php classes? For instance I would like to change blockcart so that it can be hooked on top. Since original version doesnt have that hook I need to change install() function! I can`t change original source (it would be bad idea isn't it...) file I need to override install() function by inheriting blockcart module. Is it possible to do so and where I can find example?
I use my own override to the FrontController class to allow the display of module output at arbitrary points in tpl files - this means that the module doesn't need to support a particular hook. It is implemented via a smarty plugin, so you can for example use:
{plugin module='blockcart' hook='rightColumn'}
The above will force the module to output what it would display if hooked to the right column where the above is tag inserted (which can be anywhere in any tpl file). You can "unhook" the module from the right column so that it only displays where you want it to using this technique. I have used it on a production site with great success.
There's a series of articles describing how it works (with the required code) available at:
Prestashop 1.4 Plugins
In Prestashop 1.4 you can override core classes and module templates
Today this is not possible to override a module php file but we are working on it.
in override\modules\blockcart\blockcart.php (create it if it does not exist yet)
<?php
class BlockCartOverride extends BlockCart
{
public function hookDisplayTop($params)
{
return parent::hookTop($params);
}
}
?>
like this you can override any module to be hookable on any default or custom hook.
don't forget to delete cache/class_index.php for the override to work :)
Since version 1.6.0.11 of PrestaShop, there is a new feature that allows developers to override a module’s instance classes.
Override a module’s instance class by extending it
To override a module’s instance class, you have to extend it, giving the extended class the same name and adding Override suffix:
<?php
if (!defined('_PS_VERSION_'))
exit;
class BlockUserInfoOverride extends BlockUserInfo
{
public function hookDisplayNav($params)
{
return '<div class="header_user_info"><a>Test</a></div>';
// return $this->display(__FILE__, 'nav.tpl');
}
}
Source: http://build.prestashop.com/howtos/module/how-to-override-modules/
Keep in mind that in 1.7.x era - nowadays - you can override module main classes but not controllers. To be able to override controllers you have to override the core classes (to detect any possible overrides) and then do whatever you like. Alternatively, you have to get the original files as backup and put the modified in the same place on install and the reverse procedure on uninstall.