Add custom js in head in magento2?
-
13-12-2019 - |
Question
I have custom module. I want add file my.js in folder app\code\Xanka\Slider\view\frontend\web\js\slider\my.js. I used code in app\code\Xanka\Slider\view\frontend\layout\default.xml
<head>
<title>My Slideshow</title>
<script src="Xanka_Slider::js/slider/jquery.themepunch.plugins.min.js"/>
</head>
is not true.
Solution
if want to add js file then try this
<head>
<link src="Xanka_Slider::js/slider/jquery.themepunch.plugins.min.js"/>
</head>
Here instead of use using
OTHER TIPS
use below code in
view\frontend\layout\test_index_index.xml
<head>
<title>My Slideshow</title>
<link src="Xanka_Slider::js/slider/jquery.themepunch.plugins.min.js"/>
</head>
and then keep you js file in below path
pub/static/frontend/Magento/luma/en_US/Xanka_Slider/js/slider/jquery.themepunch.plugins.min.js
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange