在freemarker中使用三元运算符?
问题描述:
我只想做这样的事情:
<a href="${ a? 'a.htm' : 'b.htm'}">
答
如果您使用的是Freemarker 2.3.23或更高版本,则可以使用
If you're using freemarker 2.3.23 or newer, you can use the then
built-in:
<a href="${a?then('a.htm','b.html')}" target="${openTarget}">
如果您使用的是较早版本的freemarker,则可以使用 string
内置在:
If you're using an older version of freemarker, you can use instead the string
built-in:
<a href="${a?string('a.htm','b.html')}" target="${openTarget}">
当应用于布尔值时,内置的string
将充当三元运算符.
When applied to a boolean, the string
built-in will act as a ternary operator.