A
A
AlexAll2020-04-19 15:10:59
Yii
AlexAll, 2020-04-19 15:10:59

How to output js script before closing tag in yii2?

Hello, I need to put the js script before the closing body tag, because I need to put it after the js code of the third-party extension, which always comes after my script. And I need it the other way around
I immediately write that it doesn’t help. This is how I connect the js file to the view, the line above this is the same third-party extension
position' => \yii\web\View::POS_END

use zgb7mtr\colorPicker\ColorPicker;
$this->registerJsFile(Yii::getAlias('@web'). '/js/common.js', ['depends' => [\yii\web\JqueryAsset::className()], 'position' => \yii\web\View::POS_END]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2020-04-19
@AlexAll

You need to make an additional AssetBundle, something like the following:

namespace app\assets;
use yii\web\AssetBundle;
class CommonAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';

    public $js = [
        'js/common.js'
    ];

    public $depends = [
        'zgb7mtr\colorPicker\ColorPickerAsset'
    ];
}

And register it in the required view file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question