Jump to content

How can we check whether new hook is used or not?


Recommended Posts

There is a very nice and handy way to add new hooks to Prestashop 1.5 templates:
{hook h='nameOfTheHook'}

But how can we check whether this hook is used or not?

I need something like:
{if $nameOfTheHook}{hook h='nameOfTheHook'}{/if}

or 

{if !empty($nameOfTheHook)}
  {hook h='nameOfTheHook'}
{else}

Is that possible at all?

 

Link to comment
Share on other sites

 

should be enough to use this:

{if Hook::getModulesFromHook(Hook::getIdByName("MyHook")) != null}
{Hook::exec("MyHook")} 
{else}
do something else
{/if}

Thanks for your reply, but it doesn't alway work the way I need.

I have only one module using that hook. 

No matter, whether this module is enabled or disabled,  Hook::getModulesFromHook(Hook::getIdByName("MyHook")) != null always returns true

 

However I found another way to check whether this hook is used or not. And it works just the way I need:

{assign var='nameOfTheHook' value={hook h='nameOfTheHook'[spam-filter]
{if $nameOfTheHook}
  {$nameOfTheHook}
{else}
  smth else
{/if}
  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Hey guys

 

Is there a way to get this done

{if $nameOfTheHook}
  {$nameOfTheHook}
{else}
  smth else
{/if}

without

{assign var='nameOfTheHook' value={hook h='nameOfTheHook'[spam-filter]

Can we not check directly if the hook has anything assigned to?

Link to comment
Share on other sites

  • 3 years later...
On 7/11/2015 at 10:30 AM, gonebdg - webindoshop.com said:

You might be able to do something like this


{if {hook h="nameOfTheHook"[spam-filter]
    {hook h="nameOfTheHook"}
{else}
    {* nameOfTheHook is not available ... do something else here *}
{/if}

Not sure why need [spam-filter] but work as charm! 

p.s. need } in the end of     {if {hook h="nameOfTheHook"[spam-filter]

Link to comment
Share on other sites

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...