freemarker-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Albert Kam <moonblade.w...@gmail.com>
Subject A cautionary case for <#sep>
Date Sun, 22 May 2016 09:47:22 GMT
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.

-- 
Do not pursue the past. Do not lose yourself in the future.
The past no longer is. The future has not yet come.
Looking deeply at life as it is in the very here and now,
the practitioner dwells in stability and freedom.
(Thich Nhat Hanh)

Mime
View raw message