You can define a custom function if
that is declared like so:
<#function if cond then else="">
<#if cond>
<#return then>
<#else>
<#return else>
#if>
#function>
The function can be used in any ${...}
expression. Your code would look like so:
In contrast to @kapep, I think you should use a function, not a macro.
Macros produce (textual) output, while functions return a value that can for example be assigned to a variable, but also written to the output, so using a function is more flexible. Furthermore, the way to apply the function is much closer to using a ternary operator, which would also be used inside ${...}
expressions, not as a directive.
For example, if you need the conditional link target multiple times, it would make sense to assign it to a local variable:
<#assign targetUrl=if(a, 'a.htm', 'b.htm')/>
link 1
...
link 2
Using the function instead of the macro, @kapep's examples would look like this:
${if(someBoolean, "someBoolean is true")}
${if(someBoolean||otherBoolean, "hello,"+user.name, 1+2+3)}
<#list seq as x>
${if(x_index==0, "first", "not first")}
<#list>