API / Apache FreeMarker Interview questions
What is the purpose of the #import directive?
<#import "/lib/utils.ftl" as utils> loads another template as a reusable library and binds its top-level variables and macros to a namespace variable - here, utils. Anything the imported template defines at its top level, such as <#macro formatDate>, becomes accessible as <@utils.formatDate .../>.
<#import "/lib/format.ftl" as fmt> ${fmt.money(total)}
Unlike #include, which pastes output inline and shares the caller's namespace, #import keeps the library's definitions in their own named namespace object, which avoids naming collisions and makes a template behave like a proper module of macros and functions.
More Related questions...