Register Assets In Template Of Module

I have a module and wanna to create its template.i create assets folder and it’s sub folders and layouts folder in my module and use it in layout :




use app\modules\blog\assets\BlogAsset;



my asset class is below code, after i render my layout of modules ,assets is created in web/assets but it not registered in head of html ?!





<?php

/**

 * @link http://www.yiiframework.com/

 * @copyright Copyright (c) 2008 Yii Software LLC

 * @license http://www.yiiframework.com/license/

 */


namespace app\modules\blog\assets;


use yii\web\AssetBundle;


/**

 * @author Qiang Xue <qiang.xue@gmail.com>

 * @since 2.0

 */

class BlogAsset extends AssetBundle

{


        public $sourcePath='@app/modules/blog/assets';

	public $css = [

              'css/style.css', 

	];

        

}



Thank’s for Solutions !

How have your registered the BlogAsset in your view layout? You mentioned only the use of the namespaced asset. You should also have registered this bundle in your view layout file in the beginning.




// views/layouts/main.php

use app\modules\blog\assets\BlogAsset;

BlogAsset::register($this);



maybe there is no


 $this->beginBody() 

and


 $this->endBody() 

in your layout

Yes,That’s it.

Its better to sometimes copy the Yii default app view layout file - and edit over it so you do not miss such important elements :).