1
我有一個關於大豆模板語法和解析對象的快速問題。所以我有一個對象,我想有條件地打印,看起來像這樣:if語句的大豆模板語法
{'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}
有誰知道語法來完成這樣的事情?謝謝!