Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Add a body onload event

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
jeffshead
Smarty Rookie


Joined: 06 Jul 2010
Posts: 5

PostPosted: Tue Jul 06, 2010 4:21 am    Post subject: Add a body onload event Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jul 06, 2010 12:57 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
jeffshead
Smarty Rookie


Joined: 06 Jul 2010
Posts: 5

PostPosted: Tue Jul 06, 2010 1:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jul 06, 2010 1:49 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP