Jump to content

[PS 1.7] Problems in including stylesheet and script in my module


Recommended Posts

Hello

 

I'm trying to create my first custom module and I need to add stylesheet and some scripts that I have inside the module. The folder stucture is the following:

 

verticalsidemenu

--css

--img

--js

-logo.png

-verticalsidemenu.php

-verticalsidemenu.tpl

 

This is my php file: https://pastebin.com/Fp3p95Ww

 

In the line "missing styles" I tried adding both setMedia and-or hookActionFrontControllerSetMedia as listed in this page: http://developers.prestashop.com/themes/assets/index.html

 

But looks like I can't succeed to include my styles

 

Can you tell me exactly where I should write the code in that file? Should I use setMedia or hookActionFrontControllerSetMedia

 

All this module does is adding a vertical static menu, right now to proceed I had to hardcode the link to my stylesheet in header.tpl of my theme

Link to comment
Share on other sites

Hello

 

I'm trying to create my first custom module and I need to add stylesheet and some scripts that I have inside the module. The folder stucture is the following:

 

verticalsidemenu

--css

--img

--js

-logo.png

-verticalsidemenu.php

-verticalsidemenu.tpl

 

This is my php file: https://pastebin.com/Fp3p95Ww

 

In the line "missing styles" I tried adding both setMedia and-or hookActionFrontControllerSetMedia as listed in this page: http://developers.prestashop.com/themes/assets/index.html

 

But looks like I can't succeed to include my styles

 

Can you tell me exactly where I should write the code in that file? Should I use setMedia or hookActionFrontControllerSetMedia

 

All this module does is adding a vertical static menu, right now to proceed I had to hardcode the link to my stylesheet in header.tpl of my theme

 

Hi..use your css inside header hook insted of install hook. 

 

$this->registerHook('header')

public function hookHeader()
{
          $this->context->controller->addCSS($this->_path . 'css/style.css', 'all');//path of css
}

Thanks

  • Like 1
Link to comment
Share on other sites

Hi..use your css inside header hook insted of install hook. 

 

$this->registerHook('header')

public function hookHeader()
{
          $this->context->controller->addCSS($this->_path . 'css/style.css', 'all');//path of css
}

Thanks

 

 

Thank you very much!! It works!

 

Now I have the same problem with javascript file actually...

 

I tried simply to add it to the header hook but it doesn't work, like this:

public function hookHeader()
{
          $this->context->controller->addCSS($this->_path . 'css/style.css', 'all');
          $this->context->controller->registerJavascript(.$this->name.'/js/script.js')
}
Link to comment
Share on other sites

Hi.

 

same as css include like this 

 

 

public function hookHeader()
{
          $this->context->controller->addCSS($this->_path . 'css/style.css', 'all');//path of css
          $this->context->controller->addJS($this->_path . 'js/script.js');//path of js
}

Thanks

 

It works! Thank you very much for the help man!

Link to comment
Share on other sites

  • 1 year later...
  • 3 years later...

addCSS @deprecated 1.7 This function shouldn't be used, use $this->registerStylesheet() instead

addJS @deprecated 1.7 This function has no effect in PrestaShop 1.7 theme, use $this->registerJavascript() 

Link to comment
Share on other sites

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...