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"

    <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"/>

  • 1
    you have to use inside cms_index_index.xml file – Rakesh Jesadiya Dec 12 '16 at 6:25
  • Use link instead of script tag in declaration. – Rakesh Jesadiya Dec 12 '16 at 6:29

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"

    <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"/>

|improve this answer|||||
  • 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 Dec 12 '16 at 6:41
  • Have your js file path, app\code\Vendor\Module\view\frontend\web\js? – Rakesh Jesadiya Dec 12 '16 at 6:43
  • I have included the js file in app\code\Vendor\Module\view\frontend\web\js\ – Vindhuja Dec 12 '16 at 6:45
  • please remove var folder from root and run php bin/magento setup:static-content:deploy command. Also remove your browser cache – Rakesh Jesadiya Dec 12 '16 at 6:46
  • Still I am not able to see the js files added in my custom module on viewing the page source – Vindhuja Dec 12 '16 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.