I have one asset bundle (AppAsset) which registered in my main layout (main.php) for common assets for the entire application:
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/style.css',
];
public $depends = [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
];
}
But on one certain page (not on entire app!) i need to change my jquery to a lower version and hook up other assets. And i'm registeting another asset bundle which depends on main asset bundle AppAsset in the desired view file :
class GalleryAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/gamma/style.css',
'css/gamma/noJS.css',
];
public $js = [
'js/gamma/modernizr.custom.70736.js',
'js/gamma/jquery.masonry.min.js',
'js/gamma/jquery.history.js',
'js/gamma/js-url.min.js',
'js/gamma/jquerypp.custom.js',
'js/gamma/gamma.js',
];
public $depends = [
'app\assets\AppAsset',
];
}
The question is how can i change the Jquery's version in child asset bundle GalleryAsset or in one certain view file (page)?
Thank you and God bless helpers.
You can read how to customize asset bundles in offical documentation.
But customizing through application config is not suitable here, because at that moment requested route is unknown.
You can change the necessary asset bundle at runtime using assetManager component:
Make sure to place this code before registering asset bundle related with that page.
In that case all assets depending on
yii\web\JqueryAsset
will cause registering older version.Also I recommend additionally check compatibility of used plugins with this version (it's not that old though).