小智 19
你不能有不同的#nested在宏中使用元素,每次使用它都会输出相同的文本.
如果您的目标是在宏中包含多个变量部分,则可以使用#assign元素.
允许定义正文,页眉和页脚内容的页面#macro示例:
<#macro pageTemplate header="" footer="">
${header}
<#nested >
${footer}
</#macro>
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用#assign元素定义每个部分(但无可否认,具有多个命名的#nested元素会更好).
<#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>
Run Code Online (Sandbox Code Playgroud)
结果输出将是:
This is the header.
This is the nested content.
This is the footer.
Run Code Online (Sandbox Code Playgroud)