Ad

How To Do An Inline If/otherwise (aka Ternary Operator) In Velocity?

- 1 answer

In pure Java, I could do this:

value = (a > b) ? a : b;

Whereas in Velocity, the long form would be:

#if($a > $b)          
    #set($value = $a)
#else
    #set($value = $b)
#end

Is there a short form in Velocity? I want to be able to do an if/otherwise inline.

Ad

Answer

You can do

#set($value = "#if($flag)red#{else}blue#end")
Ad
source: stackoverflow.com
Ad