Answer the question
In order to leave comments, you need to log in
How to correctly include your styles and js in a Yii2 module?
New to Yii2.
Created a module (/frontend/modules/mymodule).
How to correctly connect scripts and styles on the page of this module?
Shoveled a lot of information on this issue and porridge in my head.
At the root of the module, I created an assets folder and put style.css and script.js there.
Answer the question
In order to leave comments, you need to log in
Goodnight.
The first option is to create your own layout for the module, connect all styles and scripts in it via AppAsset.
The second is to try to include scripts with $this->registerCss and $this->registerJs
Full details here , or here
in the module settings, instead of $basePath, write:
public $sourcePath = '@frontend/modules/mymodule/assets'
//дальше как обычно
public $css = [
'css/style.css',
];
public $js= [
'css/script.js',
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question