How to add jQuery UI to an Asset Bundle

Balaji Viswanath picture Balaji Viswanath · Jan 30, 2015 · Viewed 11.2k times · Source

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',
    ];
} 

Answer

arogachev picture arogachev · Jan 30, 2015

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.