ctala
(Naito Neko)
April 21, 2014, 2:59pm
1
I am starting to examine and try the Asset Manager and Bundles , they seems really cool and clean to use.
In the folder where the assets are ( where AppAsset is at least ) I created a new assetBundle call TestAsset, if I call it from the application it works great ( it is my first time using namespaces too ).
The problem is that I need BootStrap library to be load firts, so that is why I want to add it as an dependency. Sadly until now, bootstrap always is loaded after my Javascript files, so my functions don’t work.
It is obvious that I am doing something wrong, and it seems that should be something really simple for someone that know how to do it.
If anyone can help me with this I would really appreciate it .
amnah
(Jellysandwich5+1)
April 21, 2014, 3:24pm
2
CTala:
I am starting to examine and try the Asset Manager and Bundles , they seems really cool and clean to use.
In the folder where the assets are ( where AppAsset is at least ) I created a new assetBundle call TestAsset, if I call it from the application it works great ( it is my first time using namespaces too ).
The problem is that I need BootStrap library to be load firts, so that is why I want to add it as an dependency. Sadly until now, bootstrap always is loaded after my Javascript files, so my functions don’t work.
It is obvious that I am doing something wrong, and it seems that should be something really simple for someone that know how to do it.
If anyone can help me with this I would really appreciate it .
You need to add BootstrapAsset as a dependency to your asset bundle.
For example, take a look at the sample AppAsset in the template apps:
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
ctala
(Naito Neko)
April 21, 2014, 3:39pm
3
I already did it . My Bundle is exactly like the original, only changing my cs and js files.
That is why it is weird for me.
I even added the AppAsset as a dependency and I stil lload before, not after.
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/miEstilo.css',
];
public $js = [
'js/miJS.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
'app\assets\AppAsset'
];
amnah
(Jellysandwich5+1)
April 21, 2014, 3:51pm
4
Hmm… Can you try "BootstrapPluginAsset"?
It looks like BootstrapAsset contains the css file while BootstrapPluginAsset contains the js file (along with the jquery dependency).
class BootstrapAsset extends AssetBundle
{
public $sourcePath = '@vendor/twbs/bootstrap/dist';
public $css = [
'css/bootstrap.css',
];
}
// --------------------------
class BootstrapPluginAsset extends AssetBundle
{
public $sourcePath = '@vendor/twbs/bootstrap/dist';
public $js = [
'js/bootstrap.js',
];
public $depends = [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
];
}
1 Like
ctala
(Naito Neko)
April 21, 2014, 4:06pm
5
You are right. Now is working correctly .
If any one is interested to know, here is the code :
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/miEstilo.css',
];
public $js = [
'js/miJS.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
'app\assets\AppAsset',
'yii\bootstrap\BootstrapPluginAsset',
];
And thanks again Amnah .