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

How to make different tpl depending on the name of the hook for module?

在某些模块中,我想根据挂钩的名称输出不同的信息。如何在tpl模块中写工作状态?

您可以使用该信息添加一个 smarty 变量,例如。在您将呈现 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}

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