That's a work around for the separator, but this problem is deeper
that that. Things like x?index, x?hasNext, x?itemParity, etc. don't
work either if you do filtering like that. So I plan to add closure
support (if it's technically possible...) and then you can do
something like:

  <#list hobbies?filter(i -> i != 'walk') as hobby>

Though you meant to filter lists before passing them to the
data-model, so it will also support bad practices... But I know that
in real world filtering has good uses too.


Monday, June 13, 2016, 3:55:29 AM, Albert Kam wrote:

> Hello Daniel,
>
> Thanks for the great updates !
>
> I have something in mind concerning the <#sep> directive. Is it
> possible to add a startSeparator only when the previous loop produces
> content ?
> This happens a lot when printing json hash entries. Example :
>
> <#local hobbies=['read', 'code', 'walk']>
> {
> <#list hobbies as hobby>
>     <#if hobby != 'walk>
>         'prop${hobby_index}': '${hobby}'<#sep>,<#sep>
>     </#if>
> </#list>
> }
>
> This will result in
> {
>     'prop0': 'read',
>     'prop1': 'walk',
> }
> Notice the extra comma after 'walk'.
>
> I have a workaround for this issue with adding the comma at the head
> if already had an entry:
> <#local hasEntry=false>
> <#list hobbies as hobby>
>     <#if hobby != 'walk>
>         <#if hasEntry>,</#if>
>         'prop${hobby_index}': '${hobby}'
>         <#local hasEntry=true>
>     </#if>
> </#list>
>
> This will result in
> {
>     'prop0': 'read'
>     ,
>     'prop1': 'walk'
> }
>
> The ideal directive to emultate the workaround above would look
> something like this:
> <#list hobbies as hobby>
>     <#if hobby != 'walk>
>         <#head_sep>,<#head_sep>
>         'prop${hobby_index}': '${hobby}'
>     </#if>
> </#list>
> Where <#head_sep> renderes the comma only if the previous loop had an entry.
>
> Just a suggestion.
>
> Thanks !
>
>
> On Mon, Jun 13, 2016 at 3:32 AM, Daniel Dekany <[email protected]> wrote:
>> I plan to start a voting here on 2016-06-14, for releasing 2.3.25. So
>> if anyone wants to add anything before that, inform me.
>>
>> This is what we have so far:
>> - Version history: 
>> http://freemarker.org/builds/2.3.25-nightly/documentation/_html/versions_2_3_25.html
>> - Last build: http://freemarker.org/builds/2.3.25-nightly/freemarker.jar
>>
>> --
>> Thanks,
>>  Daniel Dekany
>>
>
>
>

-- 
Thanks,
 Daniel Dekany

Reply via email to