cancel
Showing results for 
Search instead for 
Did you mean: 

Loading jQuery on specific pages

Loading jQuery on specific pages

I want to load a jQuery script on my product pages or if it's possible, on a specific categories pages. For example if I have a category for books and another for posters I want to load a specific script on all book pages but not the poster pages.

 

I appreciate any help.

2 REPLIES 2

Re: Loading jQuery on specific pages

Hello @evan_mcclure 

 

If you really want to go down the XML route and don't want to use Require JS you will need to use the following XML.

 

Create route_controller_controller

<head>
   <script src="*PATH TO YOUR SCRIPT" />   <!-- External scripts -->
   <script src="URL-HERE" src_type="url" />
</head>

Hope it helps.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

Re: Loading jQuery on specific pages

Follow Steps:

  • Logged in to your backend and open that particular category where you would like to call that static block
  • Click on Design tab of the category -> Find the Layout Update Xml -> Put below code in that. It will be your custom block on that particular category.
<referenceContainer name="main">
      <block class="Vendor\Module\Block\YourBlock" template="Vendor_Mdule::yourTemplate.phtml"/>
</referenceContainer>
  •  Add your jquery code into above template.

Hope it helps!

 

If you've found my answer useful, please give"Kudos" and "Accept as Solution"