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
asked Apr 19, 2017 at 11:08
codePhree
591 gold badge2 silver badges8 bronze badges
1 Answer 1
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
Paras Arora
8372 gold badges11 silver badges31 bronze badges
-
for my default theme I don't have view folder and default.xml on that directory. Can I use custom modulecodePhree– codePhree2017年04月19日 13:05:22 +00:00Commented Apr 19, 2017 at 13:05
-
If you are using any theme Please create these directories and file else create a moduleParas Arora– Paras Arora2017年04月19日 13:06:54 +00:00Commented Apr 19, 2017 at 13:06
-
I am thinking of future where we may update the themecodePhree– codePhree2017年04月19日 13:08:39 +00:00Commented Apr 19, 2017 at 13:08
-
Module creation is the best part for that also this xml workParas Arora– Paras Arora2017年04月19日 13:10:58 +00:00Commented Apr 19, 2017 at 13:10
-
How can I do this with custom modulecodePhree– codePhree2017年04月19日 13:26:29 +00:00Commented Apr 19, 2017 at 13:26
default