How to use a template view in prestashop? - prestashop

I want to use an existing template in prestashop (product-list.tpl), i use this code in my module controller (method: initContent() ):
$this->setTemplate(_PS_THEME_DIR_ . 'templates/catalog/listing/product-list.tpl');
But prestashop return me that error :
[PrestaShopException]
No template found for C:\wamp64\www\prestashop/themes/classic/templates/catalog/listing/product-list.tpl
at line 68 in file classes/Smarty/TemplateFinder.php
Thank's you very much for you'r help !

The problem lies with the method setTemplate(), which is calling getTemplatePath(), a method that check if the desired template is located either in the module directory or in the module directory inside the current theme.
To make it work i would simply copy the product-list.tpl inside the directory :
"YourTheme"/modules/"Your module"/views/templates/front/

Related

How to inherit OrderReceipt file from PoS app

I'm trying to inherit OrderReceipt.xml file from PoS to change the way cashier name is displayed. So far I tried this -> put the file in my module in this location: static > src > XML > orderReceipt_inherited.xml
Inside of it is this code:
And inside of my manifest file I am calling it with qweb like this:
I got no luck with it, changes are not showing on receipt. Can someone please help. Odoo version is 15.
You need to use the 'point_of_sale.assets' entry under assets.
You can find an example in the l10n_co_pos module
'assets': {
'point_of_sale.assets': [
'l10n_co_pos/static/src/js/**/*',
'l10n_co_pos/static/src/xml/**/*',
],
},
You need also to use the module name in the file path as you can see in the example above

WHMCS how to find right tpl files in pages

i'm using WHMCS and i want to make some changes in part of the page but its so hard and takes so much time for me to find the right tpl file and edit it in the template.
for example for this "search for domains" tab in this url =>
example.com/cart.php?a=add&domain=register
where is the .tpl file.
For example.com/cart.php?a=add&domain=register the file is at templates/orderforms/standard_cart/adddomain.tpl
In general, when url has cart.php, the file in cart template.
Also, you can add the following to hooks to tell you which tpl file was used for current page.
1- Create file includes/hooks/tpl_locator.php
2- Add the following code:
<?php
add_hook('ClientAreaPage', 1, function($vars) {
error_log(print_r([$vars['currentpagelinkback'],$vars['templatefile']], true), 3, __DIR__.'/tpl_file_location.log');
});
3- Visit the page you want to know which tpl file is used.
4- Result will be at file includes/hooks/tpl_file_location.log, sample below:
Array
(
[0] => /cart.php?a=add&pid=1&
[1] => configureproductdomain
)
This was tested on WHMCS 8.0
The tpl for cart.php?a=add&domain=register is actually located at /whmcs/templates/orderforms/standard_cart/domainregister.tpl if I understand your question.

How to create a smarty variable in prestashop 1.5

I am working on a button that switches view with onClick. I wish to store the last/default position in a variable in order to prevent switching to the default view state on each page refresh or navigation.
I read that I can do the following in a php file:
$myVar= -1;
$smarty->assign('myVar', $myVar);
and then use $myVar in the tpl file. But it does not work for me.
The tpl file I am working on is not part of a module and has no .php file in the prestashop root folder.
Can anyone educate me a little on smarty/php and how to create variables and use them to store button's state?
Thanks
Smarty is a PHP template engine for PHP, which facilitates the separation of presentation (XHTML/CSS) from the PrestaShop's core functions/controllers.
A template file (usually with a .tpl extension in PrestaShop) is always called by a PHP controller file (it can be a Front-end core controller or a module controller).
Example: /prestashop/controllers/front/ContactController.php
$this->context->smarty->assign(array(
'contacts' => Contact::getContacts($this->context->language->id),
'message' => html_entity_decode(Tools::getValue('message'))
));
$this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl');
We can see that this file is retrieving information from the database and assigning it to Smarty.
Then, the 'contact-form.tpl' template will display it to the visitors.
The syntax is pretty similar for modules,
example:/prestashop/modules/blocklink/blocklink.php
public function hookLeftColumn($params)
{
$this->smarty->assign('blocklink_links', $this->getLinks());
return $this->display(__FILE__, 'blocklink.tpl');
}
Also, to store values in Smarty variables, you can use the 'assign' function in two ways:
$this->context->smarty->assign('my_smarty_variable_name', $my_value);
or if you have several variables:
$this->context->smarty->assign(array('my_smarty_variable_name1' => $my_value1), ('my_smarty_variable_name2' => $my_value2));
And then in the Smarty template:
The value of my variable is {$my_smarty_variable_name|escape:'htmlall':'UTF-8'}.
The 'escape' modifier is used to avoid XSS security issues.
In order to use variables in your smarty file, you need to use for example :
$this->context->smarty->assign(
array(
'myVar' => $myvar,
'otherVar' => $otherVar
)
);
Then to use it in your tpl file you simply need to use :
<div>my var = {$myVar}</div>
To use a variable in your smarty you need to write it inside {}.

Prestashop hook and override module

I created a hook and I want to move there a module. I override the FrontController.php within the override folder (override/clases/controller/FrontController.php).
self::$smarty->assign(array(
‘HOOK_HEADER’ => Module::hookExec(‘header’),
‘HOOK_TOP’ => Module::hookExec(‘top’),
‘HOOK_NEWHOOK’ => Module::hookExec(‘DisplayNewHook’),
‘HOOK_LEFT_COLUMN’ => Module::hookExec(‘leftColumn’)
));
Then I edited the php file module to add:
function hookNewHook($params) { return $this->hookTop( $params ); }
And it works correctly. But is not there another way to do this? Because if the module is updated, the changes will be lost.
Thank you very much.
Module overriding is not possible until now. What you can do is to create a duplicate module (copying pasting :) ) and use that module with your changes. Any core module(s) you modify may lost the changes when you update the prestashop.
You'll find some help for creating a PrestaShop module there : http://doc.prestashop.com/display/PS14/Creating+a+PrestaShop+module

Opencart display one module conents into another module

I'm having custom footer module in my template. Also i'm using testimonial module in the position content bottom. I'm trying to display testimonial inside custom footer.
To do this i simply copied testimonial.tpl and testimonial.php contents and pasted into customfooter.tpl and customfooter.php
After this i'm getting errors stating
undefined variable and class name already assigned error
Did you know how to do this?
See this answer for how to do use a module in a separate modification/controller
opencart - How to manually display a module inside a template file?
You simply need to change from the common/home to your module's controller and view files
please define variable.
how can you define i will show you.
catalog > controller > header.php
for static variable
$this->load->language('common/header');
$data['text_home'] = $this->language->get('text_home');
// Where language file in assign this variable with different language foler
$data['text_home'] = $this->url->link('information/contact');
and you can tpl file in use this varible.
<?php echo $text_home; ?>
make sure 100% erorr has not facing
for dynamic variable