Issue
I'm modifying a module in Prestashop, which has folder structure like this..
css
translations
index.php
module.php
module.tpl
There is a variable $products that has an array of all the products. But it's only accessible to module.tpl which displays all the product on the homepage which I don't like.
I created a controller that redirects to a different page and a template/view/front/products.tpl to display all the products. But that $products variable is undefined in products.tpl file.
Solution
If you have created a new controller with a new template, you need to create in this controller this variable and assign this to a template, so:
In the initContent()
function of the controller you need to create the variable "$products" with the values that you need, for example:
$products = Product::getProducts($id_lang, 0, 0, 'id_product', 'DESC' );
Then, you need to assign this php variable to a Smarty variable to show the value in the tpl file. To do this we use the method used by "@Ravinder Pal" but changing the value:
$this->context->smarty->assign('products', $products);
And finally you can use this variable in the template that is assigned in the initContent() function with this:
{$products}
Hope it helps you.
Answered By - Addis Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.