我想在我的Prestashop主题的标题(header.tpl
)中获取所有类别,但似乎效果不佳......
我的代码header.tpl
:
{$childCategories= Category::getChildren(0, 0, $active = true, $id_shop = false);}
{printf($childCategories)}
问题:错误500
答案 0 :(得分:7)
您编写的代码对smarty无效。 Prestashop使用Smarty来呈现模板。如果你想避免这样的麻烦,请查看规则。此外,您在Prestashop的默认主题中有很多示例,以了解有关Smarty编码的更多信息。
正确的代码是:
{assign var='childCategories' value=Category::getChildren(1, 1, true, false)}
要传递的参数
打印要调试的变量
如果您想要调试或查看变量,可以尝试以下代码片段:
{* Print only the variable $childCategories *}
{$childCategories|var_dump}
或:
{* Print all variables *}
{debug}
答案 1 :(得分:0)
模板header.tpl
来自FrontController.php
函数displayHeader()
。
Category
并不存在,因为header.tpl
是所有网页中使用的综合模板。
您可以使用几个钩子在其中添加内容:displayHeader
,displayTop
,displayLeftColumn
,displayRightColumn
,displayFooter
。
您可以在任何模块中添加所有类别,也可以添加其中一个类别:
$category = new Category((int)Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);
$sub_categories = $category->getSubCategories($this->context->language->id);
// else code