Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put smarty-value to the javascript variable ?

Status
Not open for further replies.

JackTheRussel

Programmer
Aug 22, 2006
110
FI
Hi all.

I just started to study smarty and I find out problems right away.

I try to put smarty-value to the javascript variable like this:

page.php
Code:
$my_variable="foo";

smarty->assign("somevalue", $my_variable);
smarty->display("page.tpl);

page.tpl

Code:
{literal}
<script language="JavaScript">
var my_js_variable = ({$somevalue});
</script>
{/literal}

But when I look my_js_variable it is undefined ?

How can I set smarty-value to the js-variable ?

[/code]
 
Sorry. I should hesitate a little bit with my post.

I found the solution:

page.tpl
Code:
{literal}
<script language="JavaScript">
var my_js_variable = {/literal}{$somevalue}{literal}
</script>
{/literal}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top