0

I am facing an issue. I have custom Module in which i am trying to load CSS and JS by AppAsset but its not loading.

In my Module i have layouts folder in which i am trying to access the appasset and registering the view but its not loading. Even the asset bundle shows that assests are being loaded

Tell me what i am doing wrong. The code is as follows

namespace app\assets;

use yii\web\AssetBundle;


class AppAsset extends AssetBundle
{

    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',
        'css/bootstrap-reset.css',
        'css/style.css',
        'css/style-responsive.css',
    ];
    public $js = [
        'js/jquery.js',
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
    ];
}

my view file is as follows

<?php
use yii\helpers\Html;

use app\assets\AppAsset;

AppAsset::register($this);
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="ThemeBucket">
<link rel="shortcut icon" href="images/favicon.png">

<?php $this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>

<!--Core CSS -->



</head>

  <body class="login-body">


    <?php $this->beginBody() ?>

    <?php $this->endBody() ?>
  </body>
</html>

But the css is not loaded at all and i cant see any of the css which i defined in Asset Bundle

2
  • 1
    Try to add <?php $this->beginPage() ?> before <DOCTYPE> and <?php $this->endPage() ?> after </html> Commented May 20, 2020 at 14:22
  • See vendor/yiisoft/yii2/web/View.php line ~ 179, head meta tags are injected in content with function View::endPage() Commented May 20, 2020 at 14:26

1 Answer 1

1

Function <?php $this->head() ?> just adds a placeholder where all head meta tags, styles, scripts must be placed. When <?php $this->endPage() ?> is called it replaces placeholder with registered meta tags, styles, scripts, etc.

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

Comments

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.