Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii register CSS file, to be the last one (after assets)

Is there a way in Yii to register js or css files to load them after those loaded by the assets manager.

I use a css file to override styles from some Yii extensions, but Yii includes my file before the assets generated by the extension.

I know I can change the extension to remove the css files from the assets manager and add them manually with registerCssFile but that's not the way I want to do this.

Here's what I have :

<head>
...
    <link rel="stylesheet" type="text/css" href="/css/MY_CSS.css" />
...
    <link rel="stylesheet" type="text/css" href="/assets/8e838803/css/EXTENSION_CSS.css" />
...
</head>

Here's what I want:

<head>
...
    <link rel="stylesheet" type="text/css" href="/assets/8e838803/css/EXTENSION_CSS.css" />
...
    <link rel="stylesheet" type="text/css" href="/css/MY_CSS.css" /> <!-- the last one -->
</head>

Any help would be appreciated!

like image 767
Philippe Boissonneault Avatar asked Dec 10 '12 20:12

Philippe Boissonneault


2 Answers

Registered assets by CClientScript are always added before the title

In your case you should add your CSS after the title, to guarantee the order you want

like image 108
Asgaroth Avatar answered Oct 19 '22 23:10

Asgaroth


In Yii2, a good way to accomplish this is by using the 'depends' option on registerCssFile as shown in the documentation

$this->registerCssFile("http://example.com/css/themes/black-and-white.css", [
    'depends' => [BootstrapAsset::className()],
    'media' => 'print',
], 'css-print-theme');
like image 29
ChrisB Avatar answered Oct 19 '22 22:10

ChrisB