如何停止加载CSS文件只是在索引(yii2)

时间:2018-01-11 18:48:27

标签: css yii2 yii2-advanced-app

我想在除index之外的所有页面中加载site.css 怎么可以在actionIndex中忽略这个css加载?

我把site.css放在Assest中,所以加载所有操作

1 个答案:

答案 0 :(得分:1)

您可以使用特定的索引布局(或者您不需要appAsset的所有视图) 并在此布局中加载不涉及您不需要的CSS的不同资产

例如:在你身上你可以在你的资产目录中创建一个MyCLeanAppAsset.pho和你的特定资产

查看/布局用于管理此情况的新布局,例如:clean_main.php

    <?php
    use backend\assets\AppAsset;
    use common\widgets\Alert;
    use yii\helpers\Html;
    use yii\bootstrap\Nav;
    use yii\bootstrap\NavBar;
    use yii\widgets\Breadcrumbs;

    /* @var $this \yii\web\View */
    /* @var $content string */

    MyCleanAppAsset::register($this);  //    a invocation for a differente Asset 
    ?>
    <?php $this->beginPage() ?>
    <!DOCTYPE html>
    <html lang="<?= Yii::$app->language ?>">
    <head>
        <meta charset="<?= Yii::$app->charset ?>">

   ......
   ......

并在你的controllerAction中

   public function actionIndex()
    {
        $this->layout('clean_main'); 
        return $this->render('index');
    }