创建可以使用或不使用嵌套内容的宏的正确方法是什么?例如
<@myMacro/>
<@myMacro>my nested content</@myMacro>
Run Code Online (Sandbox Code Playgroud)
有这样的吗?或者是其他东西?
<#macro myMacro>
<#if ??????>
Before nested content
<#nested/>
After nested content
<#else/>
Nothing nested here
</#if>
</#macro>
Run Code Online (Sandbox Code Playgroud)
嵌套的内容被分配给一个变量,然后检查这个变量是否有任何内容。然后将该变量发送到输出,而不是使用另一个嵌套指令,以避免内容被处理两次。
<#macro myMacro>
<#assign nested><#nested/></#assign>
<#if nested?has_content>
Before nested content
${nested}
After nested content
<#else/>
Nothing nested here
</#if>
</#macro>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
767 次 |
| 最近记录: |