API / Apache Velocity Interview questions
Define the #set directive in Velocity?
#set assigns a value to a reference within the current scope. The value can be a literal, another reference, a method call result, or an arithmetic/string expression.
#set($count = 5) #set($fullName = "$user.firstName $user.lastName") #set($total = $price * $quantity) #set($isAdmin = $user.role == "ADMIN")
Unlike context.put() in Java, #set is executed inside the template itself while it's rendering, so it's typically used for short-lived, template-local calculations rather than for supplying the original data model. A variable defined with #set inside a #foreach or #macro block is scoped to that block by default.
More Related questions...