10

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.

Vivek Goel
  • 22,942
  • 29
  • 114
  • 186

1 Answers1

16

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

Community
  • 1
  • 1
bolinfest
  • 3,710
  • 2
  • 27
  • 40
  • Thanks! It's actually a bit worrying that the documentation is still not updated, but at least the feature is there... ^^ – TataBlack Oct 29 '12 at 16:46
  • isnt this the documentation - https://developers.google.com/closure/templates/docs/commands#let ? – radai Feb 23 '13 at 11:34