Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish an asset within a widget in Yii2

Tags:

yii2

In Yii 1 it was possible to publish an asset with:

Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.MyWidget.assets'));

How can I publish an asset within a widget in Yii2?

like image 828
Sebastian Viereck Avatar asked Dec 25 '22 00:12

Sebastian Viereck


2 Answers

In your view of your widget:

app\assets\AppAsset::register($this); // $this == the View object

Check the docs.

like image 71
deacs Avatar answered Jan 22 '23 01:01

deacs


Simplest way of doing this:

app\assets\AppAsset::register($this->getView());

It is the same way you would publish it in a view.

like image 30
Sulo Suurtee Avatar answered Jan 22 '23 00:01

Sulo Suurtee