Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get categories in a Prestashop theme

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

like image 766
tonymx227 Avatar asked Jan 29 '26 02:01

tonymx227


1 Answers

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

  1. $id_parent : The parent category id. The root id category is 1 and the home id category is 2.
  2. $id_lang: The id language. You can check it in the localization area to get the id of a language. If you have enable multiple languages, you could use the $language variable to get the id. List of global variables in Prestashop.
  3. $active: Return only the active caregories.
  4. $id_shop: The id of a shop if you have got multiple shops in an instalation.

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}
like image 89
Rufein Avatar answered Jan 31 '26 04:01

Rufein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!