Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freemarker macros with few nested elements

how can I have few different #nested elements in macros?

like image 377
Andrew Square Avatar asked Oct 29 '12 11:10

Andrew Square


1 Answers

You cant have different #nested elements in a macro, every usage of it will output the same text.

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

Example of a page #macro allowing to define the body, header and footer content :

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

You can then define each section using the #assign element (but admittedly having multiple named #nested element 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 output will be :

This is the header.
This is the nested content.
This is the footer.
like image 70
Guillaume Acard Avatar answered Oct 28 '22 03:10

Guillaume Acard