Your problem is not FreeMarker-specific. You flip the isNested
local variable (which also holds the parameter value) to true
before the recursive @test
call, and you leave if so after the recursive macro call has returned. So when the iteration of 6
and 7
comes, isNested
is already true
. You should not set the isNested
at all, just pass true
to the recursive call. Here:
<#macro test datas isNested=false>
<#list datas as d>
<#if d?is_enumerable>
Hi, I am going to be red!
<@test d true />
<#else>
<#if isNested>
<span style="color:red;">${d}</span>
<#else>
${d}
</#if>
</#if>
</#list>
</#macro>
<@test [1,2,3,[4,5],6,7] />