Using hooks in prestashop 1.6.x and 1.7.x – continued

Using hooks in prestashop 1.6.x and 1.7.x - continued
After the last article about hooks, new versions of prestashop came out and there were additions in terms of declaring hooks. These additions made it easy to create your own hooks for prestashop front office versions 1.6 and 1.7. This will be discussed in this article.


Prestashop 1.6 and 1.7 have the ability to register a hook in the loadable module code. Let’s consider an example – let’s create a hook that will be such a Smarty template of the source code theme:

Where displayPrimerHook – hook name, primermodule – module name.

For this hook processing option, when installing the module, you need to register the hook in the php code:

Hook registration happens exactly here:

And create a hook function handler:

After installing the module and calling the code from the Smarty template:

It will be processed according to the handler function code.

You can also call a registered hook in such a dynamic way from the php code:

or from Smarty template:

The code that is called by the hook must also be defined as a function.

For version prestashop 1.7, it was possible to register a hook in the theme configuration file theme.yml in hooks block. You can also write modules for this hook there, it looks like this:

Using Hooks in 1.7.x theme.yml

To call a hook from a Smarty template, use this form:

Registering a hook via a config file works when the theme is installed.

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Leave a comment

Your email address will not be published. Required fields are marked *