Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 disable Bootstrap Js, JQuery and CSS

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?

like image 403
taratula Avatar asked Nov 04 '14 11:11

taratula


People also ask

How to add bootstrap CSS&JS to the Yii widgets?

In Yii 2.0, the yii widgets that use Twitter Bootstrap CSS & JS directly, are part of the yii2-bootstrap extension, starting with yii/bootstrap namespace. For customizing bootstrap extension specific widget assets, you could configure your own assets (CSS/JS) using the new Yii Asset Manager in your Yii Config file.

How to override bootstrap or other styling defaults in Yii?

You can easily override Bootstrap or other styling defaults by changing the GridView default options. The simpler direct approach for you would be to override defaults for Yii's class configuration. You may use \Yii::$container->set to set up the needed dependencies of classes and their initial property values.

How can I change the default styling of the Yii widget?

Rather the widget uses Bootstrap HTML markup as default which you can override. An example of customizing the Yii GridView is mentioned here. You can easily override Bootstrap or other styling defaults by changing the GridView default options. The simpler direct approach for you would be to override defaults for Yii's class configuration.

How to change attributes of a class in yii2?

Of course, since these are part of the Yii2 framework, you don't want to change that file, otherwise, it will probably get updated at some stage, and all your changes would be lost. Since both of these attributes are public, you can change them from outside the class, and the easiest place to do this is in frontend/views/main.php: ` html


3 Answers

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
];
like image 132
Ali MasudianPour Avatar answered Oct 23 '22 03:10

Ali MasudianPour


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' => []
    ];
}
like image 33
Francesco Loddo Avatar answered Oct 23 '22 05:10

Francesco Loddo


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' => []
            ]
        ]
    ],
    ...
],
like image 10
PanPipes Avatar answered Oct 23 '22 04:10

PanPipes