Mikaveli Mikaveli - 7 months ago 55
Java Question

How to do an inline if/otherwise in Velocity?

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)
#set($value = $b)

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


According to this message Velocity has no ternary operator, but it says you should be able to do

#set($value = "#if($flag)red#{else}blue#end")