Module 如何向新挂钩显示现有模块?

Module 如何向新挂钩显示现有模块?,module,prestashop,Module,Prestashop,我创建了一个新的钩子,我想在钩子中添加一个现有模块(blocktopmenu) 钩子的名字是:topMenu 我在blocktopmenu.php中添加了以下内容: public function hookTopMenu($param) { global $smarty; $this->makeMenu(); $smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SE

我创建了一个新的钩子,我想在钩子中添加一个现有模块(blocktopmenu)

钩子的名字是:topMenu

我在blocktopmenu.php中添加了以下内容:

public function hookTopMenu($param)
  {
    global $smarty;
      $this->makeMenu();
      $smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH'));
      $smarty->assign('MENU', $this->_menu);
      $smarty->assign('this_path', $this->_path);
      return $this->display(__FILE__, 'blocktopmenu.tpl');
  }
  • 我已将模块添加到模块-->位置的新挂钩中

  • 然后我将其添加到override/classes/FrontController.php中:

    函数displayHeader(){ 父::displayHeader()

最后,在themes/mytheme/header.tpl中,我有:

<div class="my_top_menu">{$HOOK_TOP_MENU}</div>
{$HOOK\u TOP\u MENU}
但什么也没发生……结果是:

<div class="my_top_menu"></div>

知道怎么弄吗


谢谢!

您还需要更改模块中的安装功能以添加钩子:

public function install(){
    if (!parent::install() OR
        !$this->registerHook('header') OR
        !$this->registerHook('topMenu') )
        return false;
    return true;
}

当然,在此之后您需要卸载并重新安装模块。

很抱歉,这与:
返回(parent::install()&&&$this->registerHook('header')&&&$this->registerHook('topMenu'));
?更紧凑、更易于阅读。。
public function install(){
    if (!parent::install() OR
        !$this->registerHook('header') OR
        !$this->registerHook('topMenu') )
        return false;
    return true;
}