Answer the question
In order to leave comments, you need to log in
How to set assets for yii2 only for a specific page?
Here I have a js script that I want to see only on the main page.
How can i do this?
public $js = [
'js/jsquery-2.1.0.min.js',
'js/jquery.mobile-1.4.2.min.js',
'js/script.js',
];
Answer the question
In order to leave comments, you need to log in
In the init function, check the url, if the main one is to add
public function init()
{
if (\yii::$app->request->url == \yii::$app->homeUrl) {
$this->js[] = 'script.js';
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question