Jump to content

Recommended Posts

Hello, I've overriden the FrontController::setMedia() method to add another CSS file (so it will be linked for every themes) right after the global CSS.

 

public function setMedia(){
   ...
  $this->addCSS(array(
		_THEME_CSS_DIR_.'global.css',
		_PS_CUSTOMER_URI_.'css/style.css'
  ), 'all');
  ...
}

 

It works fine, but it's loaded before all the modules' CSS.

 

Where can I include this CSS so it's loaded last?

 

Regards,

Bastien.

Share this post


Link to post
Share on other sites

Hi Bastien,

 

Perhaps by putting first parent::setMedia(); or adding your css in displayHeader() or in preProcess() ?

 

Regards

Edited by math_php (see edit history)

Share this post


Link to post
Share on other sites

Thanks for your reply math_php.

 

parent::setMedia();
$this->addCSS(...);

=> still called before modules

 

displayHeader() is not called. Looks like it's deprecated now.

 

In postProcess(), $this->css_files is an array containing css, but not the modules ones, if I add the one, it will still appear before the modules' CSS.

 

I'll continue to dig in !

Share this post


Link to post
Share on other sites

With some debug_print_backtrace() magic, I found that the modules are called in the FrontController::initContent() method, so when I overwrite it and add the css at the end, it appears after the modules' CSS!

Edited by doobdargent (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

With some debug_print_backtrace() magic, I found that the modules are called in the FrontController::initContent() method, so when I overwrite it and add the css at the end, it appears after the modules' CSS!

 

Thank you! This worked great. For others reading this:

 

Change ps_root/override/classes/controller/FrontController.php

 

Add:

 

public function initContent()

{

parent::initContent();

$this->addCSS(_THEME_CSS_DIR_.'YOUR_STYLESHEET.css');

 

}

 

Between:

class FrontController extends FrontControllerCore

{

}

 

And place your stylesheet in:

ps_root/themes/theme_name/css/

 

Thanks doobdargent!

  • Like 2

Share this post


Link to post
Share on other sites

This is how it should be by default. Of course the global stylesheet should override the modules CSS. It's very developer-unfriendly to have to hack and override the CONTROLLERS for this.

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