Jump to content

Add CSS in the hook


Recommended Posts

Hello everybody!

 

I use a third-party template. In this template, there is a hook on the SMS page for outputting third-party content. I want to add my own CSS file when outputting content. For this I use the following code:

$this->context->controller->registerStylesheet(
   'module-mymodule-style',
   'modules/'.$this->name.'/views/css/mystyle.css',
   [
      'media' => 'all',
      'priority' => 200,
   ]
);

But on the page the file is not added. But if I display a list of СSS files on the screen, then my file is there.

$this->context->smarty->assign('mydebug', $this->context->controller->getStylesheets());
<pre>{$mydebug|print_r}</pre>

Tell me, please, how can I add my СSS file correctly to the page?

 

Thank you!

 

UPD: I forgot to write that I use Prestashop 1.7.2

Edited by Azariil (see edit history)
Link to comment
Share on other sites

I tried the example from the documentation, but it also did not work.  :(

public function hookActionFrontControllerSetMedia($params)
    {
        $this->context->controller->registerStylesheet(
            'module-mymodule-style',
            'modules/'.$this->name.'/views/css/styles.css',
            [
                'media' => 'all',
                'priority' => 200,
            ]
        );
    }
Edited by Azariil (see edit history)
Link to comment
Share on other sites

Alas, I still could not find a solution. I had to use the inline styles and output them through a template variable.

If someone knows the solution to the problem, then please tell me, because I want to write the code correctly and beautifully :) .

Link to comment
Share on other sites

Hi,

I have added folders in my module views/css and inside module php wrote below code.
 

$this->context->controller->addCSS($this->_path.'views/css/cssfilename.css');

This includes css file when I load my module in front-office.

Another way to do it like below function in module php file.
 

PrestaShop Tutorials Videos [How to do Tasks]

https://www.prestashop.com/forums/topic/907438-prestashop-tutorials-videos-how-to-do-tasks/

 

public function hookHeader ($ params)
{
     $this->context->controller->addJS($this->_path.'views/js/jsfilename.js');
     $this->context->controller->addCSS($this->_path.'views/css/cssfilename.css');
}
Edited by Zohaib-fk
Post Updated (see edit history)
  • Like 2
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...