How to declare a local variable in javascript close pattern

I began to study the javascript closure template library. Is it possible to create a local variable in the closure soy template file? I tried to use

$i=1; 

but it prints $i=1 on the screen instead of the announcement.

I looked into the examples at http://code.google.com/p/closure-templates/source/browse/trunk/examples/features.soy but did not find the same type of example.

+8
google-closure-templates
source share
1 answer

Yes, now it is possible! If you have a Closure Templates assembly 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 the 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 on using let visit the project documentation.

+13
source share

All Articles