php - Is it possible to link JavaScript files using <script src=""> in view files in yii 2
323
Firstly, I developed yii 1 applcation. In the application, I linked js files like this:
<script src="<?php echo Yii::app()->theme->baseUrl;?>/Index/script_nav.js"></script>
Is it possible to link JavaScript files using in yii 2 or should I link js files using appasset?
Answer
Solution:
yii2 provides registerJsFile() function to inlucde js files.
And Yes you can include the js files with
script
tag.but you should use
registerJsFile
, See this answer : https://stackoverflow.com/a/28142370/3143384Answer
Solution:
You can use that in layout file
Path
Like simple as
For checking its linked or not use inspect element -> network (open this before landing page)
Here you can see your files.