如何根据模块挂钩的名称来制作不同的tpl?

时间:2019-03-20 21:13:25

标签: prestashop smarty prestashop-1.7

在某些模块中,我想根据钩子的名称来输出不同的信息。如何在tpl模块中编写工作条件?

2 个答案:

答案 0 :(得分:0)

您可以使用该信息添加一个聪明的变量,例如。在将要渲染tpl的钩子中,您可以执行以下操作:

$this->context->smarty->assign('hook_origin', 'your-hook-name');
return $this->display(__FILE__, 'views/templates/hook/myTemplate.tpl');

现在在tpl myTemplate.tpl中,您可以评估源代码挂钩:

{if $hook_origin == 'your-hook-name'}
    {* Your code for this hook here *}
{elseif $hook_origin == 'your-other-hook-name'}
    {* Your code for this hook here *}
{else}
    {* Your code for others *}
{/if}

答案 1 :(得分:0)

如果要更改模块的PHP文件,则需要在主题中覆盖该模块。并停用Prestashop的默认模块。 通过根据主题覆盖模块,您可以完全控制PHP和模板文件。

相关问题