API / Apache Velocity Interview questions
What is the difference between local and global (library) Velocimacros?
Both are defined the same way, with #macro(name params) ... #end, but they differ in scope and where they're declared.
| Aspect | Local macro | Global (library) macro |
| Defined in | Directly inside the template that uses it | A separate .vm file registered via velocimacro.library |
| Visibility | Only that one template, by default | Every template rendered by the engine |
| Best for | One-off helpers specific to a single page | Shared UI components used across many templates |
| Override behavior | Can shadow a global macro of the same name if velocimacro.permissions.allow.inline is enabled | Provides the default implementation everyone else falls back to |
Most non-trivial applications register at least one library file, since it avoids redefining common components like pagination controls or form field wrappers in every template that needs them.
More Related questions...