Jump to content

PS 1.7 - Problems adding CSS to a module front office


Recommended Posts

Hi,

I am making my own modified version of the stock blockreassurance module. Right now it is working, but I am still unable to add a .css file with the styling for this module.

While looking for a solution, I tried a few things before posting here:

1) Call addCss() inside hookDisplayHeader()

public function install() 
{
	...
	$this->registerHook('header');
	...
}

public function hookDisplayHeader($params)
{
	$this->context->controller->addCss($this->_path.'views/css/my.css', 'all');
}

2) Call registerStylesheet() inside hookDisplayHeader()

public function install() 
{
	...
	$this->registerHook('header');
	...
}

public function hookDisplayHeader($params)
{
  if ('product' === $this->context->controller->php_self) {
    $this->context->controller->registerStylesheet(
      'module-myblockreassurance-style',
      'modules/'.$this->name.'views/css/my.css',
      ['media' => 'all', 'priority' => 200,]
    );
  }
}

3) The official docs way: https://devdocs.prestashop.com/1.7/themes/getting-started/asset-management/#without-a-front-controller-module

public function install() 
{
	...
	$this->registerHook('actionFrontControllerSetMedia');
	...
}

public function hookActionFrontControllerSetMedia($params)
{
  if ('product' === $this->context->controller->php_self) {
    $this->context->controller->registerStylesheet(
      'module-myblockreassurance-style',
      'modules/'.$this->name.'views/css/my.css',
      ['media' => 'all', 'priority' => 200,]
    );
  }
}

 

Am I doing something wrong?

Thanks in advance

 

 

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More