I have about 5 pages in a new Evolution 1.0.2 site that need custom Javascript in the head section of the page. Each page will have it’s own unique Javascript code. I cannot use a {{chunk}} because it can only be placed in the content section ... right? How do I add the Javascript? Surely there’s a way. There’s gotta be.
I don’t see how a TV will work since it is dependent on user input.
Thanks in advance for any advice!!
I just LOVE MODx! It's the greatest thing since the iPhone and the micro computer!
Hi, and welcome!
You’re generally on the right track with a chunk. You can usually use a chunk near your content tag if you want. If your Javascript is not in the HEAD, your page may not validate; I’ve been lax about this a few times... don’t tell anyone! You’d know better than I, as it’s your Javascript, but I would think that it would generally work whether in the HEAD or around the content.
The only problem with a chunk is lack of flexibility if you have a lot of different Javascripts you’ll need.
Yes, users filling in TV’s for this, probably asking for it, although you can set up user groups to prevent that user from seeing the TV if you want. If your client is not stupid, maybe they can be asked not to touch that funny code in that one spot (yeah, right!). I don’t typically do this, but if you edit your TV, at the bottom you’ll see Access Permissions... if you’ve already set up, say, a user group that consists of only you (the Super Admin, so to speak), then you can check that box on Access Permissions.
Here’s a random thought... if your script is almost the same on every page, you could use that block of Javascript in your template and use TV’s for the variables that differ per page. A little less fidding when editing the pages.
Good luck, Dave
A snippet would work in this situation I believe.
Create a new snippet with the code below and call it in the <head> section of your template.
Of course you would need to customize it to meet your specific requirements.
<?php
/* custom_js_include snippet
[!custom_js_include!]
*/
$docid = $modx->documentIdentifier;
$js_include_1 ='
<!-- js_include_1 -->
<!--[if lt IE 7]>
<script type="text/javascript" src="assets/templates/test1/jquery/jquery.js"></script>
<script type="text/javascript" src="assets/templates/test1jquery/jquery.dropdown.js"></script>
<![endif]-->
<!-- /js_include_1 -->
';
$js_include_2 ='';
$js_include_3 ='';
$js_include_4 ='';
$js_include_5 ='';
switch($docid){
case '1': $modx->regClientStartupScript($js_include_1);
break;
case '2': $modx->regClientStartupScript($js_include_2);
break;
case '3': $modx->regClientStartupScript($js_include_3);
break;
case '4': $modx->regClientStartupScript($js_include_4);
break;
case '5': $modx->regClientStartupScript($js_include_5);
break;
default: '';
return;
}
?>
nice 2 minds same solution hehe
Wow! You all totally ROCK! You guys are Royally Cool and then some!!!
This is just what the doctor ordered! Thanks so much!!!
I just LOVE MODx! It's the greatest thing since the iPhone and the micro computer!