DEV Community

zohanto
zohanto

Posted on

Change bootstrap theme in Yii2 Apllication

Yii2 is a PHP framework that until now, april 2021, still use bootstrap 3. If you are okay with that, then Yii2 is an awesome framework. Yii2 give you flexibility to handle javascript and css through AssetBundle, a feature that i didnt found in another major framework like laravel, symphony etc.

BootstrapAsset is Yii2 AssetBundle to handle bootstrap css. Luckily we can configure the BootstrapAsset through web.php config file. Say that you want to apply theme to the bootstrap 3 you already have. You got a cool free theme from bootswatch.com and want apply that to your Yii2 apps. So this is what you need to do.

  1. create folder inside @app/views folder for example we create 'flatly' folder here for your flatly theme

  2. create 'css' folder inside the previous

  3. create 'bootstrap.css' file inside the 'css' folder then copy the theme style into this file

  4. add bellow line at the end of if (YII_ENV_DEV) definition inside the web.php config file

$config['components']['assetManager']['bundles']['yii\bootstrap\BootstrapAsset']['sourcePath'] = '@app/views/flatly';
Enter fullscreen mode Exit fullscreen mode

thats it

Top comments (0)