Jump to content

How to add a new hook?


Recommended Posts

Hi

I'm very new to presta shop and have just installed and begun to build a theme. I need to create a new hook, so in my database I've added a new item in the ps_hook section and this shows up within the back office section when I go to transplant a module (you can see it in the dropdown menu - it's called 'Navbar').

I've also added {$HOOK_NAVBAR} into themes>mytheme>header.tpl and added 'HOOK_NAVBAR' => Module::hookExec('navbar'), into header.php located in the root directory. However when I try to hook a module into this hook it doesn't appear. Is there something else I need to do?

Thanks

Jon

Link to comment
Share on other sites

Paul,

Thanks for the reply so is there a way of adding code into a module so I can use a new hook? I'm new to the whole hook system and it seems very limiting, I simply want to add a horizontal navbar but I've already used the hook_TOP and HOOK_LEFT_COLUMN in the header to hold other modules so how could I place a navigation menu without creating a new custom hook?

Thanks - sorry really new to presta shop

Jon

Link to comment
Share on other sites

You could modify an existing module, although you'll need to remember you did this when you upgrade ;)

before the end of the class declaration (last }) you could try adding something like:

public function hookNavBar($params)
{
  return $this->hookLeftColumn($params);
}



That is assuming that the output the module would put in the left column is what you want moved into your new "hook". Basically all you're doing is getting the module to do the same thing when called for your new hook as it would do if called in it's "proper" location.

Paul

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...