According to the FreeMarker include
statement docs, you can make header- and footer- aware templates like so:
<#include "/header.ftl">
<!-- Content of my this page -->
<#include "/footer.ftl">
But if my web app has hundreds of pages/views, this is a lot of redundant copy pasta. It would be great if there was like a "layout" concept in FreeMarker, where I could say "Hey, here is a layout:"
<#include "/header.ftl">
<@import_FTL_Somehow>
<#include "/footer.ftl">
And then create separate templates for each view/page (index.ftl
, contactUs.ftl
, etc.) and then tell FreeMarkers which FTL files "use" the layout. That way I wouldn't have to keep specifying header/footer includes in each and every template file.
Does FreeMarker support this kind of concept?
addAutoImport
method: "Adds an invisible #import templateName as namespaceVarName at the beginning of all templates. The order of the imports will be the same as the order in which they were added with this method." However, I'm still not understanding its exact usage:it sounds like this will only import one template (either the header or the footer, but not both). – Crusade