API / Apache Velocity Interview questions
When should you use #parse over #include?
Choose based on whether the target file needs its own VTL evaluated.
| Scenario | Directive |
| Static legal text, license notice, plain snippet | #include |
| Shared header/footer/nav that itself uses $references or #if | #parse |
| Content with $ or # characters that must appear literally | #include |
| Fragment that needs access to the calling template's context variables | #parse |
Reaching for #parse when the content is truly static costs a small, unnecessary amount of parsing overhead and risks re-interpreting stray $ or # characters in that file as VTL syntax. Reaching for #include when the fragment actually needs logic will just print directives literally instead of executing them, which is a common source of confusion for teams new to Velocity.
More Related questions...