Reputation: 5451
I'd like to get all my categories in my header (header.tpl
) of my Prestashop theme but it seems not working well...
My code header.tpl
:
{$childCategories= Category::getChildren(0, 0, $active = true, $id_shop = false);}
{printf($childCategories)}
Issue : Error 500
Upvotes: 3
Views: 7502
Reputation: 1136
A template header.tpl
comes from FrontController.php
function displayHeader()
.
Category
doesn't exists there, because header.tpl
is a comprehensive template used in all pages.
There are several hooks which you can use adding content there: displayHeader
, displayTop
, displayLeftColumn
, displayRightColumn
, displayFooter
.
You can add all categories in any module and one of these hooks like that:
$category = new Category((int)Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);
$sub_categories = $category->getSubCategories($this->context->language->id);
// else code
Upvotes: 0
Reputation: 209
The code you have written is not valid for smarty. Prestashop uses Smarty to render templates. Please, take a look to the rules if you want to avoid troubles like this. Also, you have a lot of examples in the default theme of Prestashop to learn more about coding in Smarty.
The right code would be:
{assign var='childCategories' value=Category::getChildren(1, 1, true, false)}
Arguments to be passed
Printing variables to debug
If you want debug or see the variables, you could try the following snippets of code:
{* Print only the variable $childCategories *}
{$childCategories|var_dump}
or:
{* Print all variables *}
{debug}
Upvotes: 7