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

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>
5
  • for my default theme I don't have view folder and default.xml on that directory. Can I use custom module
    – codePhree
    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
    – codePhree
    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
    – codePhree
    Commented Apr 19, 2017 at 13:26

Your Answer

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

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