在Prestashop主题中获取分类

时间:2016-02-05 13:40:55

标签: smarty prestashop

我想在我的Prestashop主题的标题(header.tpl)中获取所有类别,但似乎效果不佳......

我的代码header.tpl

{$childCategories= Category::getChildren(0, 0, $active = true, $id_shop = false);}
{printf($childCategories)}

问题:错误500

2 个答案:

答案 0 :(得分:7)

您编写的代码对smarty无效。 Prestashop使用Smarty来呈现模板。如果你想避免这样的麻烦,请查看规则。此外,您在Prestashop的默认主题中有很多示例,以了解有关Smarty编码的更多信息。

正确的代码是:

{assign var='childCategories' value=Category::getChildren(1, 1, true, false)}

要传递的参数

  1. $ id_parent:父类别ID。 root id类别为1,home id类别为2.
  2. $ id_lang:id语言。您可以在本地化区域中查看它以获取语言的ID。如果您启用了多种语言,则可以使用$ language变量来获取ID。 Prestashop List of global variables
  3. $ active:仅返回活跃的护理。
  4. $ id_shop:如果您在安装中有多家商店,则为商店的ID。
  5. 打印要调试的变量

    如果您想要调试或查看变量,可以尝试以下代码片段:

    {* Print only the variable $childCategories *}
    {$childCategories|var_dump}
    

    或:

    {* Print all variables *}
    {debug}
    

答案 1 :(得分:0)

模板header.tpl来自FrontController.php函数displayHeader()

Category并不存在,因为header.tpl是所有网页中使用的综合模板。

您可以使用几个钩子在其中添加内容:displayHeaderdisplayTopdisplayLeftColumndisplayRightColumndisplayFooter

您可以在任何模块中添加所有类别,也可以添加其中一个类别:

$category = new Category((int)Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);
$sub_categories = $category->getSubCategories($this->context->language->id);
// else code