2

I am trying to integrate a custom theme on YII2 basic app.

I have two layouts, the main layout and other is login layout.

Now I don't need a css file say xyz.css on login layout but it gets loaded there and my design is getting messed up. Any proper way of disabling it on that one layout?

I am registering my css files from AppAsset.php file.

the css section look like

    public $css = [
        'themes/mytheme/assets/css/xyz.css',
        'themes/mytheme/assets/css/main.css'
    ];
hs19
  • 187
  • 2
  • 13

1 Answers1

2

Step - 1: Create LoginAsset.php in assets Folder.

LoginAsset.php

In this file, Keep those .css & .js which is required for login.

<?php
namespace app\assets;
use yii\web\AssetBundle;

class LoginAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
    'css/include-your-css-if-any.css'
    ];
    public $js = [
      'js/include-your-js-if-any.js',
    ];
}

Step - 2: Since, you told that you are having one more layout i.e. login layout. So, Use LoginAsset.php in your login layout, Like:

login.php (One out of two layouts i.e. main/login.php)

<?php
use yii\helpers\Html;

use app\assets\LoginAsset;
LoginAsset::register($this);
?>
<?php $this->beginPage() ?>
.
. // Your code

Step - 3: If even though it didn't worked. Then,

Include

<?php
use app\assets\LoginAsset;
LoginAsset::register($this);
.
.
?>

on top of your view file.

Related Search

Community
  • 1
  • 1
Nana Partykar
  • 10,175
  • 8
  • 43
  • 73