Dynamically Change Yii2 Theme

Published on Author Code FatherLeave a comment
Dynamically Change YII2 Theme, change theme in yii2 framework. Here you can learn how to change theme in yii2 Dynamically.
  1. Create a themes directory in web folder in frontend or backend where you want to change theme.

  2. place your theme folder inside themes directory.

  3. change $css and $js variables in AppAsset.php in assets folder in frontend or backend like:

    public $css = [
    public $js = [
  4. Do not include core bootstrap css, bootstrap js and jquery js as these are core APIs that are provided by Yii2. I have commented them above.

  5. Use the below code to reference theme resources (css, js, images etc) in your main.php layout file or other site pages:

        <?= Yii::getAlias('@web/themes/theme_folder') ?>/images/margo.png
  6. There is no need to include css or js files in layouts->main.php file 🙂



Leave a Reply

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