S
S
sergeysd2016-08-11 17:36:45
Yii
sergeysd, 2016-08-11 17:36:45

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

2 answer(s)
D
Dmitry, 2016-08-13
@slo_nik

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

A
artursharipov, 2020-10-29
@artursharipov

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 question

Ask a Question

731 491 924 answers to any question