简体   繁体   中英

Soy Template syntax for if statement

I have a quick question regarding Soy template syntax and parsing an object. So I have an object I would like to conditionally print that looks like this:

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

I was wondering how I could test against the first argument of 'paragraph'. I would like to conditionally call a subtemplate based on that parameter. For example

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

I would like to try and do something like this:

 /**
  * 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}

Does anyone know the syntax to accomplish something like this? Thanks!

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

{if $textItem  == 'paragraph'}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM