首页 > 解决方案 > Yii2 - wrong order of loaded CSS - extension's CSS breaks the layout

问题描述

Yii2 (v2.014), hail812/yii2-adminlte3, kartik-v/DatePicker.

Any page with a rendered datepicker breaks the theme. The font is smaller as expected, some other issues are noticable. I have found out, that the datepicker add additional css files in the html header. But instead of placing these lines AFTER the theme, they popup before all other "<link rel=stylesheet" lines. This is probably the reason for the broken layout. Is there any way to controll which order are the CSS files from plugins/extensions loaded?

标签: phphtmlcssyii2yii2-advanced-app

解决方案


Yii的做法是使用AssetManager

AssetManager允许您在php类和应用程序配置中配置捆绑包。如果您使用的是基本模板,那就是config/web.

您可以将扩展资产包配置为依赖于您想要包含在它们之前的那些,例如:

'components' => [
    'assetManager' => [
        'bundles' => [
            'kartik\date\DatePickerAsset' => [
                'depends' => [
                    'yii\web\YiiAsset',
                    'yii\bootstrap\BootstrapAsset'
            ],
        ],
    ],
],

上面的代码块kartik\date\DatePickerAsset只是一个示例,您需要找到您要配置的其他资产的名称并添加它们。


推荐阅读