Yii2 disable Bootstrap Js, JQuery and CSS
Asked Answered
S

3

40

Same as title, i don't want using bootstrap.css and bootstrap.js. I try using:

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],
    ],
],

It remove bootstrap.css but can't remove bootstrap.js. Somebody can help me?

Spherule answered 4/11, 2014 at 11:47 Comment(0)
L
90

In web.php config file add the following code into components array:

'assetManager' => [
        'bundles' => [
            'yii\bootstrap\BootstrapPluginAsset' => [
                'js'=>[]
            ],
        ],
    ],

To be more comprehensive:

in order to disable Css (bootstrap.css):

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],
    ],
],

in order to disable JS (bootstrap.js):

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapPluginAsset' => [
            'js'=>[]
        ],
    ],
],

in order to disable JQuery (jquery.js)

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'js'=>[]
        ],
    ],
],

In order to have all of them disabled:

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'js'=>[]
        ],
        'yii\bootstrap\BootstrapPluginAsset' => [
            'js'=>[]
        ],
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],

    ],
],

UPDATE

As Soju mentioned in comments, another alternative way would be disabling these files in AppAsset class, which is located in ./assets/, then remove the following lines:

public $depends = [
   'yii\web\YiiAsset',              #REMOVE
   'yii\bootstrap\BootstrapAsset',  #REMOVE
];
Lactase answered 4/11, 2014 at 12:13 Comment(9)
Why does this give me: Invalid Call – yii\base\InvalidCallException Setting read-only property: yii\web\Application::assetManager?Manthei
How would i achieve this in Yii v1.1.15?Cypher
No need to modify assetmanager for this... You juste have to modify app asset bundle...Safelight
Did you read this ? yiiframework.com/doc-2.0/…Safelight
To disable bootstrap you simply have to remove it from $depends in AppAssetSafelight
It works, you should remove all bootstrap widget/bundle use from your app.Safelight
Please note: Afaikt: If we don't want to have Yii 2 to load their Jquery version, removing 'yii\web\YiiAsset' will do nothing. Jquery will still load.Plane
Make sure your assetManager array in components!@IvoRenkemaLaryssa
I don't want to load Bootstrap CSS in Yii2. I could'nt found the correct file to paste this update. Can anyone share the path of the config file ? Thanks in advanceElboa
O
11

For anyone that gets "Invalid Call" errors you have to add Ali's answer to 'components' in $config variable in app/config/web.php E.g.

'components' => [
    'assetManager' => [
        'bundles' => [
            'yii\web\JqueryAsset' => [
                'js'=>[]
            ],
            'yii\bootstrap\BootstrapPluginAsset' => [
                'js'=>[]
            ],
            'yii\bootstrap\BootstrapAsset' => [
                'css' => []
            ]
        ]
    ],
    ...
],
Oleson answered 9/12, 2014 at 20:28 Comment(1)
This is true only for the basic templatePrior
B
11

On AppAsset.php file add this:

public function init()
{
    parent::init();
    // resetting BootstrapAsset to not load own css files
    \Yii::$app->assetManager->bundles['yii\\bootstrap\\BootstrapAsset'] = [
        'css' => [],
        'js' => []
    ];
}
Bigg answered 26/5, 2015 at 20:54 Comment(3)
This is a cleaner option, than changing config files and may be used to reset bootstrap from themesMorsel
where do I put that? inside the class AppAsset??Tamworth
\Yii::$app->assetManager->bundles['yii\\bootstrap4\\BootstrapAsset'] = [ 'css' => [], 'js' => [] ];Ritualize

© 2022 - 2024 — McMap. All rights reserved.