Use ternary operator in freemarker?

If you’re using freemarker 2.3.23 or newer, you can use the then built-in:

<a href="https://stackoverflow.com/questions/17539686/${a?then("a.htm','b.html')}" target="${openTarget}">

If you’re using an older version of freemarker, you can use instead the string built-in:

<a href="https://stackoverflow.com/questions/17539686/${a?string("a.htm','b.html')}" target="${openTarget}">

When applied to a boolean, the string built-in will act as a ternary operator.


Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)