Hello.

I have two AssetBundle. The first one is the parent, used in the general layout (main.php) to connect the same assets on all pages:

class AppAsset extends AssetBundle { public $basePath = ' @web root'; public $baseUrl = ' @web '; public $css = [ 'css/style.css', ]; public $depends = [ 'yii\web\JqueryAsset', 'yii\bootstrap\BootstrapAsset', ]; } 

The second is a child; it is used for the photo gallery page, there you need to use your assets, in addition to the main ones, and most importantly, change jquery to the version below. I connect it to the view in which the contents of the photo gallery page are displayed. The bundle itself:

 class GalleryAsset extends AssetBundle { public $basePath = ' @web root'; 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', ]; } 

How can I redefine the version of jquery in a child asset bundle or, which is the same, on one photo gallery (view) I need (on one page only)?

Thank.

    5 answers 5

    I override jQuery like this:

     class Jquery extends JqueryAsset { public $js = [ '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', ]; public $jsOptions = ['position' => \yii\web\View::POS_HEAD]; } 

      Customizing Asset Bundles

      • @VasyOk, Please try to write more detailed answers. - Nicolas Chabanovsky

      In view, you can call:

       unset($this->assetBundles['yii\web\JqueryAsset']); 

      And there it is more convenient - either to add the necessary jQuery through another bundle, or simply through the <script> tag. The method, of course, clumsy, but it seems to work. But I would change or finish the plugin that does not want to work with the current jQuery - this is a more correct way.

        But it is impossible to simply determine what the controller and the action is from the information from the $ this- »context, and then, with checking this condition, register this or that bundle in the layout? In addition, there is a kind of publishOptions in the bundle, I do not remember what it is responsible for, look in the documentation, maybe this is what you need

          It is necessary to remove:

           public $depends = [ 'app\assets\AppAsset', ];