Well, I declared all my CSS and JavaScript stuff in AppAsset but I can't make it to display the css and js links in the in the front-end view. Here are my files:
app/assets/AppAsset.php:
<?php
namespace app\assets;
use yii\web\AssetBundle;
class AppAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'assets/css/bootstrap.min.css',
'assets/plugins/weather-icon/css/weather-icons.min.css',
...
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
and here is my layout (app/modules/admin/layouts/admin.php):
<?php
use app\assets\AppAsset;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php $this->head() ?>
<?= $this->render('partials/head') ?>
</head>
<body class="tooltips">
<?= $this->render('partials/colour_panel') ?>
<div class="wrapper">
<?= $this->render('partials/top_navbar') ?>
<?= $this->render('partials/left_sidebar') ?>
<?= $this->render('partials/right_sidebar') ?>
<div class="page-content">
<div class="container-fluid">
<?= $content ?>
<?= $this->render('partials/footer') ?>
</div>
</div>
</div>
<?= $this->render('partials/scripts') ?>
</body>
</html>
<?php $this->endPage() ?>
Thanks in advance!
I had same issue. In my case layout has no <?php $this->beginBody() ?>
and <?php $this->endBody() ?>
sections inside <body></body>
tags.
It should be like this:
<body>
<?php $this->beginBody() ?>
<!--content-->
<?php $this->endBody() ?>
</body>
Hope it helps somebody
This part
<?php $this->head() ?>
should copy them in the head automatically. Are you sure the paths that you use are correct?
public $sourcePath = '@vendor';
public $css = [
'assets/css/bootstrap.min.css',
means that your files are found in the vendor/assets/css/bootstrap.min.css are you sure that is right? as that looks wrong to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With