Mikaveli Mikaveli - 4 months ago 27
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)
#else
#set($value = $b)
#end


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

Answer

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")
Comments