This macro provides a more straightforward way to do ternary operations:
<#macro if if then else=""><#if if>${then}<#else>${else}#if>#macro>
It's easy to use and looks nice and quite readable:
<@if someBoolean "yes" "no"/>
Note that it is @if
- and not #if
as in the built-in directive. Here are some more examples.
<@if someBoolean "someBoolean is true"/>
<@if (someBoolean||otherBoolean) "hello,"+user.name 1+2+3 />
<@if someBoolean then="yes" else="no" />
<#list seq as x>
<@if (x_index==0) "first" "not first"/>
<#list>
For some reason you can't add parenthesis around nameless parameters, if they are non-boolean expressions. That could have increased readability even more.