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

how to use javascript variables in smarty tags ?

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
Smitty28
Smarty n00b


Joined: 12 May 2005
Posts: 2

PostPosted: Thu May 12, 2005 12:53 pm    Post subject: how to use javascript variables in smarty tags ? Reply with quote

Hello for all.

I'm just new in this forum and already have a question:

how can I use javascript variables within a smarty tag ?

e.g.:

in a javascript-function i get the parameter "displine".

the function shall take a value from the smarty-array an display it to the browser.

-----

{literal}

<script type="text/javascript">
function DisplayTheLine (displine)
{

{/literal}

document.write('The value of the line is: '+{$linearray[displine].LINE_VALUE});

document.write('<BR>');

{literal}

}
</script>

{/literal}


-----


But smarty does not know displine within the smarty-tag {$linearray...}

How can I solve that problem ?

Thanks a lot for your help !

Smitty28
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu May 12, 2005 1:37 pm    Post subject: Reply with quote

I know this doesn't solve the problem, but at the time the template is parsed, javascript variables have no values. Smarty sees javascript as text, just like any other HTML. Only after the templates rendered, the browser picks up the resulting text and executes the javascript.

Also, this:

{$linearray[displine].LINE_VALUE}

Will certainly not work, as [displine] would be a section name in Smarty, not a variable index.
Back to top
View user's profile Send private message Visit poster's website
Smitty28
Smarty n00b


Joined: 12 May 2005
Posts: 2

PostPosted: Fri May 13, 2005 8:20 am    Post subject: Reply with quote

Hmmm...

sounds logical.

So I'l try to do a workaround.

Thanks a lot for the info, it was nevertheless helpful.

Much Greetings
Smitty
Back to top
View user's profile Send private message
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 -> Tips and Tricks 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