I have added 'jquery-1.10.2.min.js' in app\code\Vendor\Module\view\frontend\web\js\default.xml file for showing a pop up on clicking Add to Wishlist button for product in home page. But on including custom js, the default 'Add to Cart' , 'Remove Item' is not working in My Wishlist section. Is it possible to include js file only for home page by removing the file default.xml
The following is my default.xml file.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="vendor_Module::js/jquery-1.10.2.min.js"/>
<script src="vendor_Module::js/jquery.easing-1.3.pack.js"/>
<script src="vendor_Module::js/jquery.mousewheel-3.0.4.pack.js"/>
<script src="vendor_Module::js/jquery.fancybox-1.3.4.pack.js"/>
</head>
</page>
-
1you have to use inside cms_index_index.xml fileRakesh Jesadiya– Rakesh Jesadiya2016年12月12日 06:25:01 +00:00Commented Dec 12, 2016 at 6:25
-
Use link instead of script tag in declaration.Rakesh Jesadiya– Rakesh Jesadiya2016年12月12日 06:29:58 +00:00Commented Dec 12, 2016 at 6:29
1 Answer 1
You have to create cms_index_index.xml file to declare js inside your hompeage,
Using cms_index_index.xml file You can display all js inside Homepage only.
Your xml path would be below,
app\code\Vendor\Module\view\frontend\layout\cms_index_index.xml file
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<link src="Vendor_Module::js/jquery-1.10.2.min.js"/>
<link src="Vendor_Module::js/jquery.easing-1.3.pack.js"/>
<link src="Vendor_Module::js/jquery.mousewheel-3.0.4.pack.js"/>
<link src="Vendor_Module::js/jquery.fancybox-1.3.4.pack.js"/>
</head>
</page>
-
I have included the above content in app\code\Vendor\Module\view\frontend\layout\cms_index_index.xml file. On viewing page source of the home page, the js files are not included. I am getting an error in console as 'ReferenceError: jQuery is not defined'Vindhuja– Vindhuja2016年12月12日 06:41:32 +00:00Commented Dec 12, 2016 at 6:41
-
Have your js file path, app\code\Vendor\Module\view\frontend\web\js?Rakesh Jesadiya– Rakesh Jesadiya2016年12月12日 06:43:15 +00:00Commented Dec 12, 2016 at 6:43
-
I have included the js file in app\code\Vendor\Module\view\frontend\web\js\Vindhuja– Vindhuja2016年12月12日 06:45:29 +00:00Commented Dec 12, 2016 at 6:45
-
please remove var folder from root and run php bin/magento setup:static-content:deploy command. Also remove your browser cacheRakesh Jesadiya– Rakesh Jesadiya2016年12月12日 06:46:14 +00:00Commented Dec 12, 2016 at 6:46
-
Still I am not able to see the js files added in my custom module on viewing the page sourceVindhuja– Vindhuja2016年12月12日 06:55:44 +00:00Commented Dec 12, 2016 at 6:55