Problem when injecting CSS files into a Prestashop 1.6 module

0

I'm customizing a copy of Prestashop 1.6 default template. I created a module called "elpsocialmedia", the module runs well only until I have to inject the CSS files. I am using the code that is seen in all the forums:

$this->context->controller->addCSS(($this->_path)."elpsocialmedia.css", "all");

On the respective hook, but it does not work. If I add CSS files in other Prestashop modules such as "BlockCart" or if I include the hooks in the FrontController , it also injects them correctly.

The problem is when I try to inject CSS into custom modules.

I attach the code, thanks for the attention.

Note: I try to inject files wrongly but it does not show me any errors either.

modules / elpsocialmedia / elpsocialmedia.php

class ElpSocialMedia extends Module
{

    public $lsocial = array();

    public function __construct(){
        $this->name = "elpsocialmedia";
        $this->tab = "front_office_features";
        $this->author = "Elephants Noirs";
        $this->version = "0.1";
        $this->need_instance = 0;
        $this->boostrap = true;

        $this->ps_version_compliancy = array("min"=>"1.6");

        parent::__construct();

        $this->displayName = $this->l("Social Media Elephants");
        $this->description = "Manage social media";

        $this->lsocial = array(
            'youtube' => array(
                'url'=> '#',
                'icon' => 'fa-youtube'
            ),
            'facebook' => array(
                'url'=> '#',
                'icon' => 'fa-facebook'
            ),
            'instagram' => array(
                'url'=> '#',
                'icon' => 'fa-instagram'
            ),
            'googleplus' => array(
                'url'=> '#',
                'icon' => 'fa-google-plus'
            ),
            'linkedin' => array(
                'url'=> '#',
                'icon' => 'fa-linkedin'
            )
        );


        Cache::clean("hook_module_list");
    }

    public function getContent(){
        return $this->display(__FILE__, "getContent.tpl");
    }

    public function install(){

        return (parent::install() 
               && $this->registerHook("displayNav")
               && $this->registerHook("displaySectionSlider"));

    }

    public function uninstall(){
        if( !parent::uninstall() )
            return false;

        return true;
    }

    public function hookDisplayNav(){

        $this->context->controller->addCSS(($this->_path)."elpsocialmedia.css", "all");


        $assign = array(
            'lsocial' => $this->lsocial,
            '_path'=> $this->_path
        );

        $this->context->smarty->assign( $assign );

        return $this->display(__FILE__, "elpsocialmedia-nav.tpl");
    }


    public function hookDisplaySectionSlider(){

        $this->context->controller->addCSS(($this->_path)."elpsocialmedia.css", "all");

        $this->context->controller->addJS(($this->_path)."views/js/sliderheader.js");
        /*$varsAssign = array(
                'images'=> $images,
                'urlcss'=> $this->_path."views/css/sliderheader.css"
            );

        $this->context->smarty->assign( $varsAssign );*/

        return $this->display(__FILE__, "elpsocialmedia-slider.tpl");

    }

}
    
asked by Richard Rivas 24.05.2017 в 22:47
source

2 answers

0

Keep in mind that according to that route the file should be located in

modules\mimodulo\mimodulo.css

It is always better to add the file / s css on the hook

hookDisplayHeader
    
answered by 10.06.2017 в 23:32
0

Remove the last function and add the following:

    public function hookDisplaySectionSlider()
    {
        $varsAssign = array(
            'images'=> $images,
            'urlcss'=> $this->_path."views/css/sliderheader.css"
        );

        $this->context->smarty->assign( $varsAssign );
        return $this->display(__FILE__, "elpsocialmedia-slider.tpl");

   }

    public function hookHeader()
    {
       $this->context->controller->addCSS($this->_path."elpsocialmedia.css", "all");
       $this->context->controller->addJS($this->_path."views/js/sliderheader.js");
    }

Also modify install ():

    public function install(){
        return (parent::install() 
               && $this->registerHook("displayNav")
               && $this->registerHook("displaySectionSlider")
               && $this->registerHook("Header"));
    }

With this you should have it. Oh! And do not forget to reinstall the module or manually register the hook header

    
answered by 14.06.2017 в 03:55