Opencart display one module conents into another module - 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

Related

How to use a template view in 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/

Global variables in Intellij templates

I am trying to create some variables similar to the predefined ones that come with the IntelliJ templating system. I am looking to create a variable called $MY_NAME_AND_EMAIL where I can define it once and then reference it in different templates. Is this possible?
I have tried creating an include called AuthorName.txt:
#set($MY_NAME_AND_EMAIL = "Name <email#example.com>")
Then, in one of my templates, I put the following line at the top:
#parse("AuthorName.txt")
Further down the file, I use ${MY_NAME_AND_EMAIL} in the header. However, when I create a new file base on that template, it still prompts me for the name and email field, even though I set it in an include file and added the #parse directive. What am I doing wrong?

Smarty Templates - Variable Inside Variable?

So I am currently doing a custom WHMCS template that uses the smarty template system. One of the calls is as follows:
{$customfield.input|replace:'>':'placeholder="Placeholder' >'}
Now this works in that it sets the placeholder with the text Placeholder. What I am trying to achieve is to get the following variable inside where the Placeholder text is:
{$customfield.name}
So I need something like the following:
{$customfield.input|replace:'>':'placeholder="{$customfield.name}" >'}
but that doesn't work.
Is this possible?
Correct way to do it
{$customfield.input|replace:'>':"placeholder='`$customfield.name`' >"}
Drop the braces around the second variable:
{$customfield.input|replace:'>':'placeholder="{$customfield.name|escape:html}" >'}

prestashop mail customisation, and module translation

i have two question
1 - i installed referral program module , and i would like to customise the referralprogram-invitation.html mail template
so i putted the new template under : prestashop_root/themes/my_theme/modules/referralprogram/mails/referralprogram-invitation.html
but i doesn't work !
2 - i would like to add some extra text to the program page of referral program module
so i copied the file already included with the module under
prestashop_root/themes/my_theme/modules/referralprogram/translations/fr.php and I added the new text translation in this form
$_MODULE['<{referralprogram}prestashop>program_MD5'] = 'new text';
and it does not work?!!
You only forgot the language folder. Your mail templates must not be in :
prestashop_root/themes/my_theme/modules/referralprogram/mails/referralprogram-invitation.html
but in
prestashop_root/themes/my_theme/modules/referralprogram/mails/fr/referralprogram-invitation.html
If you want to add text to the program page, you must:
First, make a copy of the file : prestashop_root/modules/referralprogram/views/templates/front/program.tpl to prestashop_root/themes/my_theme/modules/referralprogram/views/templates/front/program.tpl
Then, you need to modify this file and add the text you want, where you want. To be translatable, your text must be added like this {l s='new text' mod='referralprogram'}.
Finally, you need to translate this text via the Localization > Traductions page of your BO and not directly in the fr.php file.
Do not hesitate if you need more information,
Paul.

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 {}.