Freemarker Macros with Multiple Nested Elements

How can I have several different #nested elements in macros?

+7
source share
1 answer

A macro cannot have different #nested elements, each of which will output the same text.

If you run it to have multiple variable sections in your macro, you can use the #assign element.

An example of a #macro page that allows you to define the contents of the body, header, and footer:

<#macro pageTemplate header="" footer=""> ${header} <#nested > ${footer} </#macro> 

You can then define each section using the #assign element (but admittedly having multiple named #nested elements would be better).

 <#assign headerContent> This is the header. </#assign> <#assign footerContent> This is the footer. </#assign> <@pageTemplate header=headerContent footer=footerContent> This is the nested content. </@pageTemplate> 

The resulting result will be:

 This is the header. This is the nested content. This is the footer. 
+17
source

All Articles