Creating custom hooks in Prestashop 1.5 and 1.6 – the easy way

Creating custom hooks in Prestashop 1.5 and 1.6 – the easy way

In Prestashop 1.4 when you were addding new hook, you had to insert the hook into ‘ps_hook’ database table and then create override for FrontController.php.

In Prestashop 1.5 and 1.6, you can create the new hook directly in your module and then use it anywhere in your theme or in your module.

Here is an example for own module with custom hook.

First you have to registrer the hook in the install function of the module. This module will be using default hook ‘leftColumn’ and register new hook ‘myCustomHook’:

public function install() {
if (!parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('myCustomHook'))
return false;
return true;
}

Then you have to create function to define what will be displayed in this hook, here it will be content of nameofmynewmodule.tpl file:

public function hookMyCustomHook($params)
{
return $this->display(__FILE__, 'nameofmynewmodule.tpl');
}

Now you can add the new hook into any tpl file of your theme, e.g. header.tpl. It will display the content of nameofmynewmodule.tpl

{hook h='myCustomHook'}
  • Nati Mask

    Missing opening “(” after the if statement in the code.
    Thanks for the post