Yii2-Bootstrap And Bootstrap 3 Theme

As a first time users of Yii2, I’m trying to integrate a Bootstrap 3 theme based upon a custom variables.less file with the Yii2-bootstrap extension.

I can tell that through composer, Yii2-bootstrap has triggered the inclusion of vendor/twbs/bootstrap which it most likely is loading.

My guess is that I need to use the asset manager to have it compile my custom set of *.less files which comprise the Bootstrap 3 CSS part of framework. However it’s not clear to me how to have the asset manager ignore the default Bootstrap 3 library and use my custom files. Secondly I’m not sure where these custom files should be stored within the directory tree.

You can read the asset manager documentation… you can override your own asset files to be used in asset bundles. For example, you can set this in the components section of your config file:




'assetManager' => [

    'bundles' => [

        'yii\bootstrap\BootstrapAsset' => [

             'sourcePath' => null,

             'css' => ['/path/to/your/custom/bootstrap.min.css']

        ],

    ]

]



Thanks Kartik V. I managed to switch off the general Bootstrap web sources from the vendor dir.

I’ve taken the original BootstrapAssets.php file from the yii2-bootstrap extension and copied it to frontend/assets/BootstrapAssets.php, but this file is not getting processed. Only when I rename it to AppAssets.php it is processed. This is not ideal as it blocks me from adding any other assets to my app. Not sure how is supposed to be setup in Yii2.




<?php

namespace frontend\assets;


use yii\web\AssetBundle;


/**

 * @author Qiang Xue <qiang.xue@gmail.com>

 * @since 2.0

 */

class AppAsset extends AssetBundle

{

    public $sourcePath = '@app/assets/bootstrap3/less';

    public $css = [

        'bootstrap.less',

    ];

    public $js = [

    ];

    public $depends = [

        'yii\web\YiiAsset',

        'yii\bootstrap\BootstrapAsset',

    ];

}



Solved: forgot to register is in the template (http://www.yiiframework.com/doc-2.0/guide-assets.html)