Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare local variable in closure javascript template

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.

like image 603
Vivek Goel Avatar asked Aug 12 '11 11:08

Vivek Goel


1 Answers

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

like image 129
bolinfest Avatar answered Sep 28 '22 00:09

bolinfest