API / Apache Velocity Interview questions
What are Velocity directives?
Directives are the control-flow instructions in VTL, always prefixed with #. They're what let a template do more than just print values.
| Directive | Purpose |
#set | Assign a value to a variable |
#if / #elseif / #else | Conditional branching |
#foreach | Loop over a collection |
#include | Insert a file's raw, unparsed content |
#parse | Insert and render another template's VTL |
#macro | Define a reusable Velocimacro |
#stop | Halt rendering immediately |
#break | Exit the current loop or macro block early |
Every directive is closed either implicitly (single-line #set) or with an explicit #end for block directives like #if and #foreach.
More Related questions...