我想獲得我的所有類別在我的頭(header.tpl
),但似乎都不盡如人意......獲取類別在我的Prestashop主題的題材的Prestashop
我的代碼header.tpl
:
{$childCategories= Category::getChildren(0, 0, $active = true, $id_shop = false);}
{printf($childCategories)}
問題:錯誤500
我想獲得我的所有類別在我的頭(header.tpl
),但似乎都不盡如人意......獲取類別在我的Prestashop主題的題材的Prestashop
我的代碼header.tpl
:
{$childCategories= Category::getChildren(0, 0, $active = true, $id_shop = false);}
{printf($childCategories)}
問題:錯誤500
您寫的代碼對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}
謝謝你完美的作品。 ;) – tonymx227
模板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
這個解決方案很好,但我認爲它有一個缺點:你必須開發一個模塊。如果要修改結果的結果,此解決方案會更好,例如,創建類別的自定義過濾器。但是如果你沒有任何特殊功能,最簡單的方法就是通過靜態調用。 – Rufein
是的,但是如果您想讓您的系統安全地進行主題升級,開發模塊是首選方式。 –
你檢查你的Apache的錯誤日誌文件?你正在使用哪種版本的Prestashop? –
我使用的是最新版本,錯誤是'Category'不存在......但我可以在哪裏發送類別到模板? – tonymx227