Yii2主题集成 [英] Yii2 theme integration

查看:36
本文介绍了Yii2主题集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 Yii2 高级应用程序,现在我想更改后端主题.我怎样才能做到这一点?是否有任何文件需要告诉 Yii2 使用我的自定义主题?我在 backend/web/themes/mytheme 下建立了我的主题.我只是在 advanced/backend/config/main.php 中替换了这段代码,但什么也没发生!

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',
    ],
  ], 

然后我在common/config/main.php下替换了这段代码,但没有任何改变!

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

推荐答案

在 Yii2 中另一种改变主题的方法是:

Yet another approach to change theme in Yii2 is:

  1. 在要更改主题的前端或后端的 web 文件夹中创建一个主题目录.

  1. Create a themes directory in web folder in frontend or backend where you want to change theme.

将您的主题文件夹放在主题目录中.

place your theme folder inside themes directory.

更改前端或后端资产文件夹中 AppAsset.php 中的 $css 和 $js 变量,例如:

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'
];

  • 不要包含核心 bootstrap css、bootstrap js 和 jquery js,因为这些是 Yii2 提供的核心 API.我已经在上面评论过了.

  • 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.

    使用以下代码在您的 main.php 布局文件或其他网站页面中引用主题资源(css、js、图像等):

    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
    

  • layouts->main.php 文件中无需包含 css 或 js 文件:)

  • There is no need to include css or js files in layouts->main.php file :)

    这篇关于Yii2主题集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆