Charis
Charis

Reputation: 137

Custom Hooks in Prestashop 1.7

I try to create a custom Hook for Prestashop 1.7.0.3 for the slider module. I insert:

displaySlider: - ps_imageslider

on theme.yml file on block “hooks”. Then insert:

{if $page.page_name == 'index'} 
   {hook h='displaySlider'}
{/if} 

on theme/templates/layouts/layout-both-columns.tpl file between header and section id=”wrapper” tags. According to this article: Custom Hooks in Prestashop 1.7 everything will work ok but the hook is not shown on available hooks when i try to change slider module position from the backend.

Upvotes: 3

Views: 12878

Answers (4)

Manuel
Manuel

Reputation: 127

So just to be clear. To add a new hook in Prestashop.

  1. In \themes\yourTheme\config\theme.yml you add
 
    custom_hooks:
          - name: displayYourCustomHook
          - title: displayYourCustomHook
          - description: This is a Custom hook

  1. In the same file, in the section modules_to_hook:
 displayYourCustomHook:
        - ps_moduleIwantoHook
        - ps_anotherModuleIwantToHook

  1. Wherever in your .tpl files you want to add your hook:
 
...
   {hook h='displayYourCustomHook'}
...
  1. Finally, from you backoffice, you change from your current theme to a differente one, and then save. After that, you change to the previous theme (the theme you actually want to use), save again and your hook should be visible. This is done with the aim of "refreshing" the hooks that your Prestashop site recognasizes.

This is working in Prestashop 1.7.7

Upvotes: 3

user109764
user109764

Reputation: 664

I see I voted myself for the accepted solution 2 years ago, but now came up with a much better solution. According to Prestashop 1.7 hooks doc all you have to do is to register your hook as any other normal and it will be automatically created. So paste something like:

$this->registerHook('displayAtSpecificPlace');

in your module install() and reinstall the module.

Upvotes: 0

I spent a lot of time looking for why my custom hook did not appear on the front, thanks for the tip.

In order to improve the process, you can use the reset button in appearance > themes & logo.

This avoids having to activate another theme.

Upvotes: 0

KelzoJP
KelzoJP

Reputation: 126

I was working today on the same issue.

And i succeed to make it appear, it is probably not the good way and i hope it is not the good way because it is weird.

In your theme.yml you have to set your hook like this :

global_settings:
  hooks:
    custom_hooks:
      - name: displayFooterBefore
        title: displayFooterBefore
        description: Add a widget area above the footer

And if you wanna see your hook in the position page, you have to switch to a other template and back to your one. (Kind of refresh)

You can also check the incomplete doc from Prestashop : http://developers.prestashop.com/themes/hooks/index.html

I hope there is a another way to refresh hooks in this page...

Upvotes: 7

Related Questions