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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Always Welcome @hs19 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.