2

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>
asked Dec 12, 2016 at 6:23
2
  • 1
    you have to use inside cms_index_index.xml file Commented Dec 12, 2016 at 6:25
  • Use link instead of script tag in declaration. Commented Dec 12, 2016 at 6:29

1 Answer 1

0

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>
answered Dec 12, 2016 at 6:29
9
  • 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' Commented Dec 12, 2016 at 6:41
  • Have your js file path, app\code\Vendor\Module\view\frontend\web\js? Commented Dec 12, 2016 at 6:43
  • I have included the js file in app\code\Vendor\Module\view\frontend\web\js\ Commented 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 cache Commented 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 source Commented Dec 12, 2016 at 6:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.