Tuesday, February 8, 2022

[FIXED] Yii2: Preventing a specific CSS file from getting loaded

Issue

I need to stop loading the bootstrap.css file in one view to void duplicate. But I don't know how to do that in Yii2.

I used this function in Yii 1:

Yii::app()->clientScript->scriptMap = array(
    'main.css' => false
);

Solution

If you need to disable the CSS specific to core bootstrap in a view then add the following on top of your view file like this

Yii::$app->assetManager->bundles['yii\bootstrap\BootstrapAsset'] = false;

and if you need to disable the bootstrap core js sources also then use

Yii::$app->assetManager->bundles['yii\bootstrap\BootstrapPluginAsset'] = false;


Answered By - Muhammad Omer Aslam

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.