开发者

How to declare local variable in closure javascript template

开发者 https://www.devze.com 2023-03-27 21:20 出处:网络
I started learning closure javascript template library . Is it possible to create local variable inside a closure template soy file ?

I started learning closure javascript template library . Is it possible to create local variable inside a closure template soy file ? I t开发者_开发问答ried 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

0

精彩评论

暂无评论...
验证码 换一张
取 消