Yii2: registerJsFile from bower source

Created on 20 Nov 2014  路  4Comments  路  Source: yiisoft/yii2

I'm not use AppAsset for javascipr library, but how to call js file from bower
I write :

$this->registerJsFile('/bower/flot/jquery.flot.js', [
    'baseUrl' => '@vendor',
    'depends' => 'yii\jui\JuiAsset',
]);
//or
$this->registerJsFile(Yii::$app->request->baseUrl .'/vendor/bower/flot/jquery.flot.pie.js', [
    'depends' => 'yii\jui\JuiAsset',
]);

Not working

Most helpful comment

you can publish full dirictory.

list(,$url)=Yii::$app->assetManager->publish('@bower/flot');
$this->registerJsFile($url.'/jquery.flot.js', ['depends' => 'yii\jui\JuiAsset']);
$this->registerJsFile($url.'/another.js', ['depends' => 'yii\jui\JuiAsset']);
$this->registerJsFile($url.'/jquery.etc.js', ['depends' => 'yii\jui\JuiAsset']);

for more simple register. create AssetBundle for your js (and css).

All 4 comments

list(,$url)=Yii::$app->assetManager->publish('@bower/flot/jquery.flot.js');
$this->registerJsFile($url, ['depends' => 'yii\jui\JuiAsset']);

Thanks for your suggest
But is there a simple way ?
What if many library to register ?

you can publish full dirictory.

list(,$url)=Yii::$app->assetManager->publish('@bower/flot');
$this->registerJsFile($url.'/jquery.flot.js', ['depends' => 'yii\jui\JuiAsset']);
$this->registerJsFile($url.'/another.js', ['depends' => 'yii\jui\JuiAsset']);
$this->registerJsFile($url.'/jquery.etc.js', ['depends' => 'yii\jui\JuiAsset']);

for more simple register. create AssetBundle for your js (and css).

Thanks :+1:

Was this page helpful?
0 / 5 - 0 ratings