Search code examples
phpprestashophook

Registering hook in Prestashop module


I am trying to register header hook to display my text:

//install function
return parent::install() &&
            $this->registerHook('header');
public function hookHeader()
    {
        $this->context->controller->addJS($this->_path.'/views/js/front.js');
        $this->context->controller->addCSS($this->_path.'/views/css/front.css');
    }

what that I get when trying to transparent:

Hooks are already registered


Solution

  • I think you should use : actionFrontControllerSetMedia / actionAdminControllerSetMedia to register yours js and css.

    public function install()
    {
        return parent::install() &&
            $this->registerHook('actionAdminControllerSetMedia');
    }
    public function hookActionAdminControllerSetMedia()
    {
        $this->context->controller->addJS($this->_path.'/views/js/front.js');
        $this->context->controller->addCSS($this->_path.'/views/css/front.css');
    }