API / Apache FreeMarker Interview questions
What is the purpose of the #include directive?
<#include "path/to/file.ftl"> textually inserts the output of another template directly into the current one at that point, similar to pasting a header or footer fragment into the page. It runs in its own local scope for variables declared with #assign/#local inside it, but it shares the surrounding namespace's existing variables, so values already assigned in the calling template are visible to the included file.
<#include "/common/header.ftl"> <h1>${pageTitle}</h1> <#include "/common/footer.ftl">
It is the simplest way to reuse layout fragments like headers, footers, or navigation menus across many pages.
More Related questions...