if语句的大豆模板语法

时间:2012-02-17 14:03:33

标签: javascript html templates

我有一个关于Soy模板语法和解析对象的快速问题。所以我有一个我想条件打印的对象,如下所示:

{'paragraph':'Some important text that you want printed.'},

我想知道如何测试'段落'的第一个参数。我想基于该参数有条件地调用子模板。例如

{'list':['item 1', 'item 2']}

我想尝试做这样的事情:

 /**
  * Prints the text object specified.
  * @param textToPrint All of the items you want rendered on the page.
  */
 {template .printText}
    {foreach $textItem in textToPrint}
      {if $textItem[0] is 'paragraph'}          //THIS IS THE LINE IN QUESTION
         {call .paragraph}
            {param paragraph: $textItem[0] /}
         {/call}
      {else}
         {call .list}
            {param listItem: $textItem[0] /}
         {/call}
      {/if}
    {/foreach}
  </ul>
 {/template}

有谁知道完成这样的事情的语法?谢谢!

1 个答案:

答案 0 :(得分:0)

好吧,我想这应该是这样的:

{if $textItem  == 'paragraph'}