How to manage assets in yii2 theme. Is there any easy way to manage custom javascript and css in yii2?
How to manage assets in yii2 theme. Is there any easy way to manage custom javascript and css in yii2?
How can I add bootstrap JS file to layout or view with AssetBundle?
if I add
public $js = [
'js/bootstrap.js',
];
to BootstrapAsset it’s work fine but after composer update it will gone.
maybe new AssetBundle? it’s not pretty.
To load bootstrap of jquery asset you have to declare a dependency from your Asset class to jquery or bootstrap:
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
// your css files here
];
public $js = [
// your js files here
];
public $depends = [
// 'yii\web\YiiAsset', // this loads yii javascript
'yii\bootstrap\BootstrapAsset', // this loads bootstrap
];
}
How to add bootstrap and custom css and js in custom theme in yii2?
In yii2 theme manager not found.
my theme location is web/themes/admintheme
I could do that partially by commenting asests in AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
// ‘yii\bootstrap\BootstrapAsset’,
];
}
and then directly add files in html main.php.
But i am still looking forward to learn more about assetBundle
Hi
When Registering assets, js files included in end of body , is there any way to move to head ?
Add this in asset
public $jsOptions = ['position' => \yii\web\View::POS_HEAD];