Re: inserting separator between lis
"Jonathan Revusky" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Something like this?
<#macro join delimiter = ", ">
<#local input>
<#nested>
</#local>
<#list input?split("\n") as line>
<#if line?trim != "">
${line?trim}<#t>
<#if line_has_next>
${delimiter}<#t>
</#if>
</#if>
</#list>
</#macro>
<@join>
a
b
c
d
</@join>
outputs
a, b, c, d
(And, of course, the ?split built-in can use regular expressions to
split, so far trickier split/join situations could be handled than the
above example... )
JR
On Tue, Jun 24, 2008 at 11:07 PM, Zemian Deng <[email protected]> wrote:
> It would be nice to have a "join" built-in method :)
>
> On Tue, Jun 24, 2008 at 5:00 PM, Zemian Deng <[email protected]> wrote:
>> Ah, got it Thanks.
>>
>> On Tue, Jun 24, 2008 at 4:16 PM, Tim Diggins <[email protected]> wrote:
>>> Hi -
>>>
>>> check out http://fmpp.sourceforge.net/freemarker/ref_directive_list.html
>>>
>>> you want to wrap , with <#if x_has_next>,</#if> just like in the
>>> example in that pae
>>>
>>> Tim
>>>
>>>
>>> On 24 Jun 2008, at 20:31, Zemian Deng wrote:
>>>
>>>> Hello list,
>>>>
>>>> I have:
>>>>
>>>> <#assign my = [0,1,2,3,4,5,6,7,8,9]/>
>>>> [<#list my as x>'${x}', </#list>]
>>>>
>>>> producing: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ]
>>>>
>>>> Is there a clean way to remove the last unwanted comma there?
>>>>
>>>> Thanks,
>>>> Z
>>>>
>>>> -------------------------------------------------------------------------
>>>> Check out the new SourceForge.net Marketplace.
>>>> It's the best place to buy or sell services for
>>>> just about anything Open Source.
>>>> http://sourceforge.net/services/buy/index.php
>>>> _______________________________________________
>>>> FreeMarker-user mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>
>>> Tim Diggins
>>> http://red56.co.uk/people/tim
>>>
>>>
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Check out the new SourceForge.net Marketplace.
>>> It's the best place to buy or sell services for
>>> just about anything Open Source.
>>> http://sourceforge.net/services/buy/index.php
>>> _______________________________________________
>>> FreeMarker-user mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>
>>
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php