【发布时间】:2018-06-27 19:04:03
【问题描述】:
我对 prestashop 有一个小问题。当用户在A类的某个子类中时,显示A类的信息(描述、标题和图片),而不是用户所在子类的信息。
使用 smarty {$category.id_parent} 我可以显示父类别的 ID,但例如,我想使用 {$category.description_parent}
你有什么建议吗? 谢谢你
【问题讨论】:
标签: prestashop categories
我对 prestashop 有一个小问题。当用户在A类的某个子类中时,显示A类的信息(描述、标题和图片),而不是用户所在子类的信息。
使用 smarty {$category.id_parent} 我可以显示父类别的 ID,但例如,我想使用 {$category.description_parent}
你有什么建议吗? 谢谢你
【问题讨论】:
标签: prestashop categories
使用模块,你不能在 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)。
【讨论】: