Add registerCssFile after asset bundles

When registering a CSS file into a view file it puts the file before the asset manager files, I was searching over the internet here but didn’t found nothing that can really work.

I’ve tried POS_HEAD but it keeps loading BEFORE the AssetManager.

How can I add the registerCssFile be added after the assetBundles of the asset manager?

Well just answering myself the simpler way to get this done is, if you need that CSS and JS files loaded from the view file to be loaded after the YiiAsset, just add the ‘depends’ option in the registerJsFile or registerCssFile like this:


$this->registerJsFile('@web/js/yourfile.js', ['depends'=> [yii\web\JqueryAsset::className()]]);

$this->registerCssFile('@web/css/yourfile/calendar.css', ['depends' => [yii\bootstrap\BootstrapAsset::className()]]);

Also is good practice to create a widget when reusing the same code lots of times.

1 Like

your way or you can add the css files to an asset file (http://www.yiiframework.com/doc-2.0/guide-structure-assets.html)