Jump to content

Load CSS last


doobdargent

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.

Link to comment
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 !

Link to comment
Share on other sites

  • 2 weeks later...

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
Link to comment
Share on other sites

  • 5 months later...

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