Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2013
    Location
    Portishead, North Somerset, United Kingdom
    Posts
    34
    Plugin Contributions
    0

    Default Importing Javascript into certain product pages, not site-wide or named pages.

    Hi everyone,

    I can't seem to find an answer for this in the forum.

    I'm trying to add specific javascript into a product page. Rather than do it site-wide, I'd like to add it on a per page basis. I've seen you can add site-wide java and page specific java (eg contact page, home page), but I cannot see if you can add "product page" specific javascript.

    Currently I have a huge amount of javascript in my tpl_product_info_display.php page which gets turned off and on using:

    <?php if ($cPath !== '90') :?>
    //Do something

    Does anyone know if this is possible without hacking apart the template pages as I'm doing?

    Many thanks

    Matt

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: Importing Javascript into certain product pages, not site-wide or named pages.

    If you want to have "conditional" javascript on the product_info page, I'd suggest creating file(s) named jscript_something.php in your store's /includes/modules/pages/product_info sub-directory.

    Those files get loaded only for the product_info page and allow you to use PHP to 'filter' what scripts are included. See examples in the /includes/modules/pages/checkout_payment sub-directory's jscript_main.php.

  3. #3
    Join Date
    Oct 2013
    Location
    Portishead, North Somerset, United Kingdom
    Posts
    34
    Plugin Contributions
    0

    Default Re: Importing Javascript into certain product pages, not site-wide or named pages.

    Thanks Lat9,

    I'll have a look into that.

    Kind Regards

    Matt

  4. #4
    Join Date
    Oct 2013
    Location
    Portishead, North Somerset, United Kingdom
    Posts
    34
    Plugin Contributions
    0

    Default Re: Importing Javascript into certain product pages, not site-wide or named pages.

    Lat9,

    You legend, many many thanks.
    Worked perfectly using both your file-set method with my existing php filtering. No longer am I wading through thousands of lines of javascript!!!!

    Sunday is now going to be a productive day!


    Just to be clear what I have done to any users:
    If you have specific javascript you'd like to load on a particular product page, you don't have to include it on every product page resulting is slower page load times etc across your site.

    Simply create a file/s named jscript_something.php and put it in the /includes/modules/pages/product_info/ folder. It will then load the java, but with the added benefit you can use the file to filter what product page it loads on, or category as I have done.

    You simply need to add something like : <?php if ($cPath == '90') :?> to the top of the file and it will only load if the category id = 90.

    Please Lat9, feel free to correct if I have it incorrect.

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: Importing Javascript into certain product pages, not site-wide or named pages.

    Nope, you got it right!

 

 

Similar Threads

  1. Implement site wide javascript
    By usr50 in forum General Questions
    Replies: 7
    Last Post: 26 Feb 2011, 03:50 AM
  2. Loading a javascript site-wide
    By ckosloff in forum General Questions
    Replies: 10
    Last Post: 12 Dec 2008, 06:56 PM
  3. Site Wide Javascript
    By traders in forum Templates, Stylesheets, Page Layout
    Replies: 14
    Last Post: 18 Nov 2007, 03:03 PM
  4. Can it be integrated into existing site's product pages?
    By MikeyJ in forum General Questions
    Replies: 2
    Last Post: 21 Sep 2006, 02:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR