|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jeffshead Smarty Rookie
Joined: 06 Jul 2010 Posts: 5
|
Posted: Tue Jul 06, 2010 4:21 am Post subject: Add a body onload event |
|
|
I purchased a script package that utilizes Smarty.
There are separate .tpl files for the header, footer, etc.
I want to add a JavaScript function to a particular template and have it called via onload. The body tag is located in the header template and the header template is included in all templates.
Is there a way to have my function called without editing the body tag in the header template? Doing so would call this function for every template/page and I only want to do that for one particular template.
I basically want to append the body tag for this one particular template only. This is the body tag in the header template: <body{$bodyload}>
Secondly, is there a way to add the JavaScript to the head tag for this particular template only? The head tag is also in the header template. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jul 06, 2010 12:57 pm Post subject: |
|
|
Code: | {include file="header.tpl" onLoad="myBodyLoad();"} |
header.tpl:
Code: | {if $onLoad ne ""}
<body onload="{$onLoad}">
{else}
<body>
{/if} |
An alternative is to move the <body> tag out of the header template and handle that in each individual template. |
|
Back to top |
|
jeffshead Smarty Rookie
Joined: 06 Jul 2010 Posts: 5
|
Posted: Tue Jul 06, 2010 1:40 pm Post subject: |
|
|
mohrt wrote: | Code: | {include file="header.tpl" onLoad="myBodyLoad();"} |
header.tpl:
Code: | {if $onLoad ne ""}
<body onload="{$onLoad}">
{else}
<body>
{/if} |
An alternative is to move the <body> tag out of the header template and handle that in each individual template. |
The body tag in header.tpl already has a variable in it.
<body{$bodyload}>
If I change it to match your suggestion, it will probably "break" something else, won't it? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jul 06, 2010 1:49 pm Post subject: |
|
|
You need to pass some sort of flag into the header to determine your different outputs. Its up to you to decide how to organize it. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|