Reputation: 1607
What is the proper way to create a macro that can be used with or without nested content? e.g.
<@myMacro/>
<@myMacro>my nested content</@myMacro>
Is there something like this? Or something else?
<#macro myMacro>
<#if ??????>
Before nested content
<#nested/>
After nested content
<#else/>
Nothing nested here
</#if>
</#macro>
Upvotes: 3
Views: 1145
Reputation: 831
The nested content is assigned to a variable and then this variable is checked if it has any content. The variable is then sent to the output instead of using another nested directive to avoid the content being processed twice.
<#macro myMacro>
<#assign nested><#nested/></#assign>
<#if nested?has_content>
Before nested content
${nested}
After nested content
<#else/>
Nothing nested here
</#if>
</#macro>
Upvotes: 6