Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

Yii2 theme integration

I have installed Yii2 advanced application, and now I want to change backend theme. How can I do this? Is there any file where I need to tell Yii2 that use my custom theme? I established my theme under backend/web/themes/mytheme. I just replaced this code in advanced/backend/config/main.php, but nothing happened!

 'view' => [
  'theme' => [
       'pathMap' => ['@app/views' => '@app/themes/mytheme'],
       'baseUrl' => '@web/themes/mytheme',
    ],
  ], 

Then I replaced this code under common/config/main.php but nothing changed!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yet another approach to change theme in Yii2 is:

  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 = [
        //'css/site.css',
        'themes/theme_folder/css/font-awesome.min.css',
        'themes/theme_folder/css/slicknav.css',
        'themes/theme_folder/css/style.css',
        'themes/theme_folder/css/responsive.css',
        'themes/theme_folder/css/animate.css',
        'themes/theme_folder/css/colors/red.css',
        //'themes/margo/asset/css/bootstrap.min.css',
    ];
    public $js = [
            'themes/theme_folder/js/jquery.migrate.js',
            'themes/theme_folder/js/modernizrr.js',
            'themes/theme_folder/js/jquery.fitvids.js',
            'themes/theme_folder/js/owl.carousel.min.js',
            'themes/theme_folder/js/nivo-lightbox.min.js',
            //'themes/theme_folder/js/jquery-2.1.4.min.js',
            //'themes/theme_folder/asset/js/bootstrap.min.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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...