Adding a Script to index.tpl

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
jlkane
Regular
Posts: 6
Joined: Sun Jul 31, 2005 7:39 am

Adding a Script to index.tpl

Post by jlkane »

I am embedding Serendipity in the framework of a new site I'm designing:
http://gs14.inmotionhosting.com/~public7/

Serendipity will be the engine behind the "Public Musings" page. But as you can see, I have a minor problem:
http://gs14.inmotionhosting.com/~public ... /index.php

I'm embedding Serendipity by adding my "framing" HTML to an index.tpl template file. Since the main site uses JavaScript rollover buttons, I've added the two required scripts to the header of the index.tpl file ...but now Serendipity fails to load, with the following message:
Fatal error: Smarty error: [in
/home/public7/public_html/Musings/templates/PublickMusick/index.tpl
line 17]: syntax error: unbalanced parenthesis in if statement
(Smarty_Compiler.class.php, line 1256) in
/home/public7/public_html/Musings/bundled-libs/Smarty/libs/Smarty.class.php
on line 1088

When I pull the scripts out, Serendipity loads fine ...but I need those scripts! What I should do to calm Smarty down here?

Thanks in advance for your help,

Jim
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding a Script to index.tpl

Post by garvinhicking »

Hi!

The smarty output is actually telling you, that you have opened more "(" than you closed in an IF statement you entered into the index.tpl.

So if you could show that piece of code, I could tell you where you need to add or remove a bracket? :)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
jlkane
Regular
Posts: 6
Joined: Sun Jul 31, 2005 7:39 am

Re: Adding a Script to index.tpl

Post by jlkane »

Thanks for the rapid reply, Garvin!

I understood the error message, but I'll be darned if I can find any evidence of an unbalanced parenthesis. :(

I hate to ask you troubleshoot script code that has worked flawlessly for me in other contexts for years, but here's what I'm inserting:

<script language="JavaScript" type="text/javascript">
<!-- hide this script from non-javascript-enabled browsers

/* Function that swaps images. */
function mOver(num) {
if (document.images) {
document.images['button'+ num].src = eval('over' + num).src;}}
function mOut(num) {
if (document.images) {
document.images['button'+ num].src = eval('normal' + num ).src;}}

/* Preload button images */
if (document.images)
{
normal1 = new Image();
normal1.src = "../buttons/Home.gif";

over1 = new Image();
over1.src = "../buttons/Home_f2.gif";

normal2 = new Image();
normal2.src = "../buttons/Who_We_Are.gif";

over2 = new Image();
over2.src = "../buttons/Who_We_Are_f2.gif";

normal3 = new Image();
normal3.src = "../buttons/Performances.gif";

over3 = new Image();
over3.src = "../buttons/Performances_f2.gif";

normal4 = new Image();
normal4.src = "../buttons/Listen.gif";

over4 = new Image();
over4.src = "../buttons/Listen_f2.gif";

normal5 = new Image();
normal5.src = "../buttons/Recordings.gif";

over5 = new Image();
over5.src = "../buttons/Recordings_f2.gif";

normal6 = new Image();
normal6.src = "../buttons/Get_Involved.gif";

over6 = new Image();
over6.src = "../buttons/Get_Involved_f2.gif";

normal7 = new Image();
normal7.src = "../buttons/News.gif";

over7 = new Image();
over7.src = "../buttons/News_f2.gif";

normal8 = new Image();
normal8.src = "../buttons/Musings.gif";

over8 = new Image();
over8.src = "../buttons/Musings_f2.gif";

normal9 = new Image();
normal9.src = "../buttons/About_the_Music.gif";

over9 = new Image();
over9.src = "../buttons/About_the_Music_f2.gif";
}
// stop hiding -->
</script>

If you can help me isolate the problem, I'll be deeply in your debt!

Jim
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding a Script to index.tpl

Post by garvinhicking »

Hi!

When you embed javascript, you must escape the "{" and "}" characters, because Smarty uses them for its own purposes!

http://smarty.php.net/manual/en/languag ... ldelim.php

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
jlkane
Regular
Posts: 6
Joined: Sun Jul 31, 2005 7:39 am

Re: Adding a Script to index.tpl

Post by jlkane »

Brilliant! I'm back in business!

Thank you, Garvin, for your seemingly limitless patience with our newbie questions. And, as always, for your rapid response!

Deeply in your debt,

Jim
spackler
Regular
Posts: 27
Joined: Fri Aug 19, 2005 8:13 pm
Location: Milwaukee
Contact:

Post by spackler »

I can out newbie you jkane :) I'm having the same problem.

jkane - Would you be able to post your solution code from the working index.tpl? I'm not having any luck with the {ldelim}{rdelim} and I'm sure I'm just placing them in the wrong place.

I also have multiple functions in my code between the
<script language="JavaScript" type="text/javascript">
and
</script> tags so maybe I need to do something slightly different?

Thanks!
jlkane
Regular
Posts: 6
Joined: Sun Jul 31, 2005 7:39 am

Post by jlkane »

It took me two tries to realize that I wasn't being instructed to "frame" the script code with a pair of {ldelim} {rdelim} bookends (as you would comment out some code).

Rather, we are asked to literally substitute the string "{ldelim}" -- without the quotes, of course -- for each and every occurrence of the "{" character in our scripts. And likewise for {rdelim}.

Not hard once you understand the principle.

Easy to do with a search-and-replace, but you have to use a two-step dance: once you've replaced, say, "{" with "{ldelim}", you can't simply replace all of the }'s with {rdelim} ...because you just injected a bunch of new ones at the end of each {ldelim}. I'm too lazy to do it all manually, so my two-step was as follows:
- replace all those }'s with a unique character (e.g., "*")
- replace all the {'s with {ldelim}
- replace all the *'s with {rdelim}
jlkane
Regular
Posts: 6
Joined: Sun Jul 31, 2005 7:39 am

Before and After

Post by jlkane »

Here's a before-and-after that should clear up any confusion I've created.

Before:

/* Function that swaps images. */
function mOver(num) {
if (document.images) {
document.images['button'+ num].src = eval('over' + num).src;}}
function mOut(num) {
if (document.images) {
document.images['button'+ num].src = eval('normal' + num ).src;}}

After:

/* Function that swaps images. */
function mOver(num)
{ldelim}
if (document.images) {ldelim}
document.images['button'+ num].src = eval('over' + num).src;{rdelim}{rdelim}
function mOut(num) {ldelim}
if (document.images) {ldelim}
document.images['button'+ num].src = eval('normal' + num ).src;{rdelim}{rdelim}
spackler
Regular
Posts: 27
Joined: Fri Aug 19, 2005 8:13 pm
Location: Milwaukee
Contact:

Post by spackler »

Jlkane, thanks for replying.

Ok, I see you are replacing the normal code with the {ldelim}{rdelim}. In diving a little deeper into the page that Garvin posted (http://smarty.php.net/manual/en/languag ... ldelim.php)

I found the {literal}{/literal} see: http://smarty.php.net/manual/en/languag ... iteral.php

Maybe a bit easier in this case?

So your AFTER code would be:

Code: Select all


{literal}
<script language="JavaScript" type="text/javascript"> 
<!-- hide this script from non-javascript-enabled browsers 

/* Function that swaps images. */ 
function mOver(num) { 
if (document.images) { 
document.images['button'+ num].src = eval('over' + num).src;}} 
function mOut(num) { 
if (document.images) { 
document.images['button'+ num].src = eval('normal' + num ).src;}} 

/* Preload button images */ 
if (document.images) 
{ 
normal1 = new Image(); 
normal1.src = "../buttons/Home.gif"; 

over1 = new Image(); 
over1.src = "../buttons/Home_f2.gif"; 

normal2 = new Image(); 
normal2.src = "../buttons/Who_We_Are.gif"; 

over2 = new Image(); 
over2.src = "../buttons/Who_We_Are_f2.gif"; 

normal3 = new Image(); 
normal3.src = "../buttons/Performances.gif"; 

over3 = new Image(); 
over3.src = "../buttons/Performances_f2.gif"; 

normal4 = new Image(); 
normal4.src = "../buttons/Listen.gif"; 

over4 = new Image(); 
over4.src = "../buttons/Listen_f2.gif"; 

normal5 = new Image(); 
normal5.src = "../buttons/Recordings.gif"; 

over5 = new Image(); 
over5.src = "../buttons/Recordings_f2.gif"; 

normal6 = new Image(); 
normal6.src = "../buttons/Get_Involved.gif"; 

over6 = new Image(); 
over6.src = "../buttons/Get_Involved_f2.gif"; 

normal7 = new Image(); 
normal7.src = "../buttons/News.gif"; 

over7 = new Image(); 
over7.src = "../buttons/News_f2.gif"; 

normal8 = new Image(); 
normal8.src = "../buttons/Musings.gif"; 

over8 = new Image(); 
over8.src = "../buttons/Musings_f2.gif"; 

normal9 = new Image(); 
normal9.src = "../buttons/About_the_Music.gif"; 

over9 = new Image(); 
over9.src = "../buttons/About_the_Music_f2.gif"; 
} 
// stop hiding --> 
</script>
{/literal}

jlkane
Regular
Posts: 6
Joined: Sun Jul 31, 2005 7:39 am

Take it Literally

Post by jlkane »

Oooo... that's MUCH cleaner ...much more what came to mind when I first saw {ldelim}{rdelim}.

Thanks, Spackler! I think I'll go back and tidy up my code now...

Jim
Post Reply