开发者

How do I use an IF statement in a loop with StringTemplate

开发者 https://www.devze.com 2022-12-08 20:03 出处:网络
This displays nothing: $Articles:{ $if(i!=1)$ 开发者_StackOverflow社区display in between articles $endif$

This displays nothing:

$Articles:{ $if(i!=1)$ 开发者_StackOverflow社区 display in between articles $endif$ $it.Text

}

This displays as expected

$Articles:{ display in between articles $it.Text

}

Any ideas on how to get this working?


you need to compute all expressions and push into the template. You are clearly filtering, which shoul be done in the model not the view. Please see:

http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf

Terence


here, it says that $if tests for the presence of an attribute or evaluates a boolean expr. The only operator allowed is !(NOT),
so maybe you can define a boolean variable = (i!=1) and use it in the $if statement.

0

精彩评论

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

关注公众号