Jump to content

How to put HOOK in module template?


Kerm

Recommended Posts

Hello, i know how do new hook and put it to the site template and all work fine, i see my module in new hook, but when i try put hook in module template i see this error:

 

Notice: Undefined variable: HOOK_HEADER_.....

 

How can i put new hook directly to the module template?

 

I just need in one module put hook to load other module...

Edited by Kerm (see edit history)
Link to comment
Share on other sites

Hello, thanks for fast reply.

 

What i do:

 

FrontController.php

 

1) Near line 500 i add:

'HOOK_HEADER_DEM' => Module::hookExec('headeruserinfo') // New Hook

 

2) After in mysql table ps_hook i add new hook

3) After in module "blockuserinfo" add new hook:

return (parent::install() AND $this->registerHook('top') AND $this->registerHook('header') AND $this->registerHook('headeruserinfo'));

 

At the end of file i add:

 

public function hookheaderuserinfo($params)
{
if (!$this->active)
return;
global $smarty, $cookie, $cart;
$smarty->assign(array(
'cart' => $cart,
'cart_qties' => $cart->nbProducts(),
'logged' => $cookie->isLogged(),
'customerName' => ($cookie->logged ? $cookie->customer_firstname.' '.$cookie->customer_lastname : false),
'firstName' => ($cookie->logged ? $cookie->customer_firstname : false),
'lastName' => ($cookie->logged ? $cookie->customer_lastname : false),
'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order'
));
return $this->display(__FILE__, 'blockuserinfo_shoo.tpl');
} 

4) After in module position i put blockuserinfo to the new hook

5) After i need place {$HOOK_HEADER_DEM} to "blockcms", i do like that:

 

<li class="shoo-myaccount">{$HOOK_HEADER_DEM}</li>

 

After turn on compile and turn off cache i see that error:

 

Notice: Undefined variable: HOOK_HEADER_DEM in /tools/smarty/sysplugins/smarty_internal_data.php on line 291

 

What i do wrong?

Link to comment
Share on other sites

you said you changed the FrontController class, around line 500, to add the smarty variable. I assume that is in the displayHeader function where the HOOK_HEADER occurs?

 

I would add a debug statement in the blockuserinfo module, where you added the hookheaderuserinfo function. You should first confirm that your hook is being executed. use the php error_log function to write the debug statements to a file.

Link to comment
Share on other sites

My FrontController.php:

 


self::$smarty->assign(array(
'HOOK_HEADER' => Module::hookExec('header'),
'HOOK_TOP' => Module::hookExec('top'),
'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'),
'HOOK_FOOTER_DEM' => Module::hookExec('footernewsletter'), // New Hook
'HOOK_HEADER_DEM' => Module::hookExec('headeruserinfo') // New Hook
));

 

If i put {$HOOK_HEADER_DEM} in site template all ok, i see module, if i put in module template "blockcms.tpl" i see error...

 

In my cms config i turn on display all erros on site, but i see only "Notice: Undefined variable: HOOK_HEADER_DEM in...."

 

At the end of blockcms.php:

 

public function hookTop()
{
 global $smarty, $cookie;
 $cms_titles = self::getCMStitles(self::LEFT_COLUMN);
 $smarty->assign(array(
  'block' => 1,
  'cms_titles' => $cms_titles,
  'theme_dir' => _PS_THEME_DIR_
 ));
 return $this->display(__FILE__, 'blockcms_shoo.tpl');
}
public function hookFooter()
{
 global $smarty;

 if (Configuration::get('FOOTER_BLOCK_ACTIVATION'))
 {
  $cms_titles = self::getCMStitlesFooter();
  $smarty->assign(array(
   'block' => 0,
   'cmslinks' => $cms_titles,
   'theme_dir' => _PS_THEME_DIR_,
   'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'),
   'display_poweredby' => ((int)Configuration::get('FOOTER_POWEREDBY') === 1 || Configuration::get('FOOTER_POWEREDBY') === false)
  ));
  return $this->display(__FILE__, 'blockcms.tpl');
 }
 return '';
}

 

If i put {$HOOK_HEADER_DEM} to footer template "blockcms.tpl" its work too, but if i put in top template "blockcms_shoo.tpl" have error..

Edited by Kerm (see edit history)
Link to comment
Share on other sites

  • 4 weeks 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...