I just learn smarty and javascript. My question is how to pass a smarty variable/value to javascript.
thanks!
[solved]passing smarty variable to javascript
Moderator: General Moderators
[solved]passing smarty variable to javascript
Last edited by mushi on Thu Feb 09, 2006 1:19 pm, edited 1 time in total.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Actually it can be and we have done it alot. You just need to use the Literal tag from smarty.
Here is a bit of javascript from our game.
When you want to insert a smarty variable into the javascript you can wrap the javascript inside a literal tag and then anywhere you would like to insert a smarty variable just use the example above for how to do it.
This isn't the only way you can do it but it does work.
Here is a bit of javascript from our game.
Code: Select all
// changeDelta function //
{literal}
<SCRIPT LANGUAGE="JavaScript">
<!--
function changeDelta(desiredvalue,currentvalue)
{
Delta=0; DeltaCost=0;
Delta = desiredvalue - currentvalue;
while (Delta>0)
{
DeltaCost=DeltaCost + Math.pow({/literal}{$upgrade_factor}{literal},desiredvalue-Delta);
Delta=Delta-1;
}
DeltaCost=DeltaCost * {/literal}{$upgrade_cost}{literal} * {/literal}{$alliancefactor}{literal};
return DeltaCost;
}
// -->
</SCRIPT>
{/literal}This isn't the only way you can do it but it does work.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm