Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 AppAsset not generating css/js links in the layout

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!

like image 958
Георги Банков Avatar asked Jan 08 '15 00:01

Георги Банков


2 Answers

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

like image 164
megapixel23 Avatar answered Oct 14 '22 17:10

megapixel23


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.

like image 28
Mihai P. Avatar answered Oct 14 '22 16:10

Mihai P.