5

I have the following asset bundle and i would like to add jQuery UI as part of it as well. How can I do it?

<?php
namespace app\assets;

use yii\web\AssetBundle;

class AdminAsset extends AssetBundle
{
    public $basePath = '@webroot/assets-admin';
    public $baseUrl = '@web/assets-admin';

    public $css = [
        'css/common.css',
        'css/animations.css',
        'css/editor.css',
        'css/form.css',
        'css/fileupload.css',
        'css/template.css',
        'css/icons.css',
    ];
    public $js = [
        'js/libs/modernizr.js',
        'js/script.js'
    ];
    public $depends = [
        'yii\web\JqueryAsset',
        'yii\web\YiiAsset',
    ];
} 
tereško
  • 58,060
  • 25
  • 98
  • 150
Balaji Viswanath
  • 1,684
  • 1
  • 12
  • 19

2 Answers2

18

At first install official JUI Extension for Yii 2.

Then add yii\jui\JuiAsset to list of dependent assets:

public $depends = [
    'yii\jui\JuiAsset',
    ...       
];

yii\web\JqueryAsset in this case is not required because JuiAsset already has it in dependencies list so it will be included as well.

arogachev
  • 33,150
  • 7
  • 114
  • 117
0

Since the accepted answer no longer works in Yii 2.10 , I will add my solution.

It is necessary now to include the CoreAsset, plus the desired jui components. The other components depend on CoreAsset so for example if you want to use draggable, do:

public $depends = [
    //'yii\jui\CoreAsset', // included as dependency of draggable
    'yii\jui\DraggableAsset',
];
111
  • 1,788
  • 1
  • 23
  • 38