gpt4 book ai didi

macros - 具有少量嵌套元素的 Freemarker 宏

转载 作者:行者123 更新时间:2023-12-01 22:19:12 25 4
gpt4 key购买 nike

如何在宏中包含几个不同的 #nested 元素?

最佳答案

宏中不能有不同的#nested元素,每次使用它都会输出相同的文本。

如果您的目标是在宏中包含多个变量部分,则可以使用 #assign 元素。

允许定义正文、页眉和页脚内容的页面示例#macro:

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

然后,您可以使用 #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>

结果输出将是:

This is the header.
This is the nested content.
This is the footer.

关于macros - 具有少量嵌套元素的 Freemarker 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13120695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com