我对prestashop有一点疑问。当用户位于类别A的子类别之一时,显示类别A的信息(描述,标题和图片),而不显示用户所在子类别的信息。
使用smarty {$category.id_parent}
我可以显示父类别的ID,但是例如,我想使用{$category.description_parent}
你有提示吗? 谢谢你
答案 0 :(得分:0)
使用模块,你不能在Prestashop的Smarty中注入PHP。您需要事先工作:
1 - 使用自定义挂钩创建模块(如displayMySuperHook)。
2 - 在模板中实现钩子:
{hook h='displayMySuperHook' current_category=$category}
3 - 在PHP中执行以下操作:
public function hookDisplayMySuperHook($params) {
if (isset($params['current_category']) && Validate::isLoadedObject($params['current_category'] && !empty($params['current_category']->id_parent)) {
$parent_category = new Category((int) $params['current_category']->id_parent);
// Maybe check Validate::isLoadedObject on parent category here
$this->context->smarty->assign(array(
"parent_category" => $parent_category,
));
return $this->display(__FILE__, 'templatename.tpl');
}
}
4 - 使用模块中所需的内容创建模板(/moduledir/views/templates/hook/templatename.tpl)。