I want to disalbe vendor-core.js in myParticular view file. I have included it in AppAsset.php. but i do not need it in particular page as it is causing some serious issues.
My need is to remove vendor-core.js in particular view file. Other Js files will be loaded as it is.
vendor-core.js is needed in mostly views. but few are important views in which i do not want to include it.
Any help will highly appriciated.
thanks in advance..
Here is my AppAsset code
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <[email protected]>
* @since 2.0
*/
class AppAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
// 'css/site.css',
'css/vendor.min.css',
'css/theme-core.min.css',
'css/module-essentials.min.css',
'css/module-layout.min.css',
'css/module-sidebar.min.css',
'css/module-sidebar-skins.min.css',
'css/module-navbar.min.css',
'css/module-media.min.css',
'css/module-timeline.css',
'css/module-chat.min.css',
'css/module-charts.min.css',
'css/module-maps.min.css',
'css/jquery-ui-timepicker-addon.css',
'css/custom.css',
];
public $js = [
'js/vendor-core.js',
'js/vendor-tables.min.js',
// 'js/vendor-forms.min.js',
'js/vendor-media.min.js',
'js/vendor-charts-all.min.js',
'js/vendor-maps.min.js',
'js/vendor-tree.min.js',
'js/vendor-nestable.min.js',
// 'js/module-essentials.min.js',
// 'js/module-layout.min.js',
'js/module-sidebar.min.js',
'js/module-media.min.js',
'js/module-chat.min.js',
'tinymce/js/tinymce/tinymce.min.js',
'js/jquery-ui-sliderAccess.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
];
//public $jsOptions =[
// 'position' => \yii\web\View::POS_READY
//];
}
You can use Init function in your AppAsset and push css or your js on conditions according to controller id and/or action id
public function init()
{
if(\Yii::$app->controller->id == 'controllerid')
{
array_push($this->css,'css-path/file.css');
array_push($this->js, 'js-path/file.js');
}
}
And for the ease in your case you can unset the same from js array instead of push in above function and it will not load in that particular action
if(($key = array_search('js-path/file.js', $this->js)) !== false) {
unset($this->js[$key]);
}