Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Loading hava script file for ez pages

Loading hava script file for ez pages

Views: 680

Results 1 to 3 of 3
16 May 2013, 6:34 PM
#1
boydbreen avatar

boydbreen

New Zenner

Join Date:
Oct 2012
Posts:
48
Plugin Contributions:
0

Loading hava script file for ez pages

Hi Everyone

I have some javascript files that only get loaded of 6 ez pages.

I caurrently have them in the footer so the are loaded last however

Is there a way that I can only load these java script when the pages that require are displayed

I tried the following bit think i may be barking up the wrong tree

if ($current_page_base == 'page' and $id == '5' or $_GET['id'] == '5' or $_GET['id'] == '15' or $_GET['id'] == 9or $_GET['id'] == '16') {
$flag_disable_jscript = flase;

<script type="text/javascript" src="includes/templates/theme407/js/mhgallery.js"></script> <script type="text/javascript" src="includes/templates/theme407/js/initgallerytvframing.js"></script> <script type="text/javascript" src="includes/templates/theme407/js/initgallerystandard.js"></script>

}

I am not sure if this will work or if I have the format correct for an ez ppage

Many Thanks

17 May 2013, 12:54 AM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Loading hava script file for ez pages

You can use the autoloader system to load the proper javascripts where you want them, without touching any existing files.

First, don't save your js files like
/includes/templates/theme407/js/mhgallery.js

In the general case where you want them loaded every time, save them like
/includes/templates/theme407/jscript/jscript_mhgallery.js

For your particular case where you only want them loaded on certain ez-pages, you need a helper file to do the testing. Then (since you don't want them autoloaded) you might name the js files in a way that will be bypassed by the auto system, say keeping your original names.
includes/templates/theme407/jscript/mhgallery.js
Make a new helper file in this folder:
/includes/modules/pages/page/jscript_mhgallery.php
with content like```php

<?php //load these js files for this set of ez-pages if ($_GET['id'] == '5' or $_GET['id'] == '15' or $_GET['id'] == 9 or $_GET['id'] == '16') { echo '<script type="text/javascript" src="includes/templates/theme407/jscript/mhgallery.js"></script> <script type="text/javascript" src="includes/templates/theme407/jscript/initgallerytvframing.js"></script> <script type="text/javascript" src="includes/templates/theme407/jscript/initgallerystandard.js"></script>'; } //EOF ``` I haven't done exactly this before, so if it doesn't work the first time, let me know and we'll tweak it. Note: you had a typo in your original code that would mess up - no space after 9 here: $_GET['id'] == 9or $_GET['id'] ==
17 May 2013, 1:05 AM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Loading hava script file for ez pages

You need to pay close attention to the way you write logic tests. Grouping alternate clauses is essential.

if ($current_page_base == 'page' and $id == '5' or $_GET['id'] == '5' or $_GET['id'] == '15' or or $_GET['id'] == '16')

Any one of these being true would let the enclosed code execute, while you intended for $current_page_base == 'page' to always be required, along with one of the ids being true. This is done with correct parentheses:

if ($current_page_base == 'page' and ($id == '5' or $_GET['id'] == '5' or $_GET['id'] == '15' or $_GET['id'] == 9or $_GET['id'] == '16')) {

$flag_disable_jscript = flase;
has no function, even without the typo. A flag by itself does nothing; it must be checked somewhere and appropriate action taken for it to be useful.