0
votes

i am newbie in prestashop module development, i want to make a module to display a custom page for maintenance page, for this i have create a hook and added it to maintenance tpl file of my theme, when i active the maintenance mode the html of my custom page display normally but it does not load neither css or js files associated with my module, when i inspect the page it shows that it does not load this files here is my code

<?php
if (!defined('_PS_VERSION_')) {
    exit;
}
class Sd_Coming_Soon extends Module{
    public function __construct(){
        $this->name                  =   "sd_coming_soon";
        $this->author                =   "name";
        $this->version               =   "1.0.0";
        $this->bootstrap             =   true;
        parent::__construct();
        $this->displayName           =   $this->l("Sd Coming Soon page");
        $this->description           =   $this->l("This module will add Coming soon page with countdown");
        $this->ps_version_compliancy =   array("min" => "1.7", "max" => _PS_VERSION_);
    }
    public function install(){
        if (!parent::install())
            return false;
        if (!$this->registerHook('displayComingSoon') or !$this->registerHook('displayMaintenance'))
            return false;
        $this->registerHook('displayMaintenance');
        return true;       
   }
   public function uninstall(){
       if(!parent::uninstall())
            return false;
       return true;
   }
   public function hookDisplayComingSoon($params){


        return $this->display(__FILE__,'views/templates/hook/coming_soon.tpl');
   }
   public function hookDisplayMaintenance($params){    
        $this->context->controller->addCSS($this->_path.'views/css/coming_soon.css', 'all');
        $this->context->controller->addJs($this->_path.'views/js/coming_soon.js', 'all');
   }

}

so i have try to add the css and js path hard coded into the maintenance tpl file, the links show up in the page when i inspect it but it does not work, the page display only raw html without any styles

2
Place the addCSS and addJS in hookDisplayComingSoon. - Crezzur
i tried this but not load either - acme project

2 Answers

0
votes

Add them in header, like:

public function hookHeader()
{
    $this->context->controller->addJS($this->_path.'/views/js/front.js');
    $this->context->controller->addCSS($this->_path.'/views/css/front.css');
}
0
votes

Use the correct Hook

Register Hook:

$this->registerHook('displayHeader')

Call your files

public function hookDisplayHeader()
{
    $this->context->controller->addJS($this->_path.'PATH.js');
    $this->context->controller->addCSS($this->_path.'PATH.css');
}

Please remember you have to reinstall your module in order to register the new hook in Prestashop