I want to access my css and javascript files in both frontend and backend.
So, my question is where i put css and javascript files so they are accessible for both frontend and backend.
Or is there any way to reuse files i.e. i put my css file in web folder of backend and use it in frontend.
Thanks
As it says here, you can make asset bundle in @common folder and set property $sourcePath, using an alias or absolute path to directory with your scripts and styles. The scripts directory may not be web-accessible.
Try something like this:
namespace common\assets;
use yii\web\AssetBundle;
/**
* Main frontend application asset bundle.
*/
class CommonAsset extends AssetBundle
{
public $sourcePath = '@common/scripts';
public $css = [
];
public $js = [
'blabla.js'
];
public $depends = [
];
}
And place your scripts to common/scripts. Also don't forget to register this asset in your layout or another view:
use common\assets\CommonAsset;
CommonAsset::register($this);
Worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With