创建一个带有可选嵌套内容的 freemarker 宏?

Creating a freemarker macro with optional nested content?

创建可以使用或不使用嵌套内容的宏的正确方法是什么?例如

<@myMacro/>
<@myMacro>my nested content</@myMacro>

有这样的吗?或者别的什么?

<#macro myMacro>
  <#if ??????>
    Before nested content
    <#nested/>
    After nested content
  <#else/>
    Nothing nested here
  </#if>
</#macro>

将嵌套的内容赋给一个变量,然后检查这个变量是否有内容。然后将变量发送到输出而不是使用另一个嵌套指令以避免内容被处理两次。

<#macro myMacro>
    <#assign nested><#nested/></#assign>

    <#if nested?has_content>
        Before nested content
        ${nested}
        After nested content
    <#else/>
       Nothing nested here
    </#if>
</#macro>