The most generic replacement for
<#if loopable_has_next>, </#if>
is
<#sep>, </#sep>
and not just
<#sep>,
If you omit </#sep>, like you did, then it's implied directly before
the </#list>. Since you had statements after that </#if>, use an
explicit </#sep> where the </#if> was.
--
Thanks,
Daniel Dekany
Sunday, May 22, 2016, 11:47:22 AM, Albert Kam wrote:
> Hi there, just want to share a cautionary case that i faced just now.
>
> <#if loopable_has_next>, </#if>
> into
> <#sep>,
>
> But bad story for me as i didnt realize <#sep>, skips all the logic
> below it on the last loop as can be seen from this simple code:
>
> <@testSep />
>
> <#macro testSep>
> <#list 1..1 as num>
> number ${num}<#sep>,
> -- This is not evaluated at the last loop --
> -- The logic below is not evaluated also --
> -- ${num * 10}
> </#list>
> </#macro>
>
> which results in "number 1" only.
>
> So, never just replace the old _has_next to <#sep> blindly like i did, ;-)
>
> Perhaps cases like this could be prevented by something like <#sep ', '> ?
>
> Anyway, a good new directive, i hated having to do _has_next all the
> time also, but just want to share this case i faced to others.
>