How to disable Bootstrap in Yii2

How to disable Bootstrap in Yii2

By default, Yii2 comes bundled with the Bootstrap framework. After installing any configuration (basic or advanced), you’ll see a start page styled with Bootstrap. In this case (and possibly in all others), there’s nothing wrong with that, since it's just a placeholder, not a production website. But what if the client or studio decides to move away from such a popular solution like Bootstrap and opts for something like MaterializeCSS instead? In that case, you’ll need to disable Bootstrap and connect the MaterializeCSS framework (or any other you prefer).

The first thing we need to do is get rid of the built-in Bootstrap setup provided by Yii developers.

The second step is to disable Bootstrap support in the asset file (in basic, it’s located at /assets/AppAsset.php):

class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',
    ];
    public $js = [
    ];
    public $depends = [
        'yiiwebYiiAsset',
        'yiibootstrapBootstrapAsset',
    ];
}

Remove the line:

'yiibootstrapBootstrapAsset',

The third step is to enable MaterializeCSS by adding the framework's CSS file path to the "$css" array, and don’t forget the "$js":

class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/materialize/css/materialize.min.css',
        'css/site.css',
    ];
    public $js = [
		'css/materialize/js/materialize.min.js',
    ];
    public $depends = [
        'yiiwebYiiAsset',
    ];
}

That’s it.

Posts on similar topics

Are you having problems with your Yii2 framework website? Do you need additional functionality?
>Then write to me via the feedback form, and I will try to help you.

Write a comment

Your email address will not be published. Required fields are marked *