Search code examples
prestashopsmartyprestashop-1.7

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


In some modules I want to make a different output of information depending on the name of the hook. How to write a working condition in the module tpl?


Solution

  • You can add a smarty variable with that information, eg. in the hook where you will render a tpl you could do this:

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

    Now in your tpl myTemplate.tpl you can evaluate the source hook:

    {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}