API / Apache Velocity Interview questions
How do you apply conditional logic in a Velocity template?
Conditional branching uses #if, optional #elseif blocks, an optional #else, and a closing #end.
#if($order.total > 100) Free shipping applied. #elseif($order.total > 50) Discounted shipping applied. #else Standard shipping rate applies. #end
Conditions support the usual comparison operators (==, !=, >, <, >=, <=) and logical operators (&&, ||, !). Velocity also treats an unset reference, an empty string, an empty collection, or Boolean false as falsy, which is often called "Velocity truth" and mirrors similar conventions in Groovy.