在freemarker中使用三元运算符? [英] Use ternary operator in freemarker?

查看:2225
本文介绍了在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.

这篇关于在freemarker中使用三元运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆