0

I am trying to add custom javascript to all product page and category page. but I don't known if to create custom magento 2 module or can edit the magento vendor module.

If I can use the two above how do i go about it

Amit Bera
77.8k21 gold badges127 silver badges240 bronze badges
asked Apr 19, 2017 at 11:08

1 Answer 1

0

Please use this code in app/design/frontend/{Vendor}/{ThemePackage}/Magento_Catalog/view/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
 <head>
 <!-- some code-->
 <!-- for including css -->
 <css src="Magento_Catalog::css/some.css"/> 
 <!-- for including js -->
 <link src="Magento_Catalog::js/slider/some.js"/>
 <!-- some code-->
 </head>
</page>
answered Apr 19, 2017 at 12:31
5
  • for my default theme I don't have view folder and default.xml on that directory. Can I use custom module Commented Apr 19, 2017 at 13:05
  • If you are using any theme Please create these directories and file else create a module Commented Apr 19, 2017 at 13:06
  • I am thinking of future where we may update the theme Commented Apr 19, 2017 at 13:08
  • Module creation is the best part for that also this xml work Commented Apr 19, 2017 at 13:10
  • How can I do this with custom module Commented Apr 19, 2017 at 13:26

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.