Mikaveli Mikaveli - 1 year ago 100
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.

Answer Source

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")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download