Jump to content

pass parameter to hook function


itps

Recommended Posts

How can i pass parameters to module hook function.

For example i have a hook displayCarrierExtraInfo which must display some extra info if carrier id=2

In theme template I call hook like this:

 

foreach $option.carrier_list as $carrier}
<div class="delivery_option_title">{$carrier.instance->name}</div>
{hook h='displayCarrierExtraInfo'}
{/foreach}

 

In module i have function

 

function hookDisplayCarrierExtraInfo($params){
return 'some extra info';
}

 

Currently in $params are all smarty and other variables but in this case I need only get carrier id what is in active template carrier loop.

 

How can i pass in template carrier id or some other parameters to hook function?

Link to comment
Share on other sites

Maybe your objective must be achieved without the use of hooks.

 

 

which must display some extra info if carrier id=2

 

It seems like you can put some smarty code instead of

{hook h='displayCarrierExtraInfo'}

to test if the carrier id = 2

 

I think the use of display hooks is that you have some place in the tpl where different modules registers to add their output. So for example when rendering product.tpl the controller does

'HOOK_PRODUCT_TAB' =>  Hook::exec('displayProductTab', array('product' => $this->product)),
'HOOK_PRODUCT_TAB_CONTENT' =>  Hook::exec('displayProductTabContent', array('product' => $this->product)),

And then every module registered will have their hookDisplay..   method called (in this case you can see the product is passed also as parameter). The result of this method will be put in the product.tpl (you have a module order, the first,the second..etc)

		{if isset($accessories) AND $accessories}<li><a href="#idTab4">{l s='Accessories'}</a></li>{/if}
		{if isset($product) && $product->customizable}<li><a href="#idTab10">{l s='Product customization'}</a></li>{/if}
		{$HOOK_PRODUCT_TAB}
	</ul>
	<div id="more_info_sheets" class="sheets align_justify">
Link to comment
Share on other sites

  • 8 months 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...