I started learning closure javascript template library . Is it possible to create local variable inside a closure template soy file ? I tried using
$i=1;
but it prints $i=1
on screen in place of declaring it.
I had looked inside examples at http://code.google.com/p/closure-templates/source/browse/trunk/examples/features.soy but didn't find same type of example.
Yes, this is now possible! If you have a build of Closure Templates that was cut in 2011, you can declare local variables as follows:
{let $first: $person.firstName /}
{$first}
Note that like {param}
, you can also define a local variable with a more complex expression between opening and closing tags:
{let $name}
{$person.firstName} {$person.lastName}
{/let}
Sometimes you need to use this form if you want to use other commands to define your variable:
{let $className}
{css name_class}
{/let}
<div class="{$name_class}"></div>
For more information about using let
visit project's documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With