Re: hash concatenation messes key ordering

John Cherouvim <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Hello again

Since I didn't find a native solution I did it by concatenating the keys 
in a separate list and using those for looking up in the concatenated 
hash in order to preserve ordering.

<#local foo={'a':'1','b':'2'} />
<#local bar={'c':'3'} />

<#local allKeys=foo?keys+bar?keys />
<#local all=foo+bar />
<#list allKeys as k>
  ${k}-${all[k]}
</#list>

prints out: a-1 b-2 c-3

thanks
Ioannis

John Cherouvim wrote:
> Hello
>
> This FreeMarker template:
> <#local foo={'a':'1','b':'2'} />
> <#local foo=foo+{'c':'3'} />
> <#list foo?keys as k>
> ${k}
> </#list>
>
> prints:
> b c a
>
> Would it be possible to concatenate 2 hashes in FreeMarker but retain 
> the key ordering? (so it would print "a b c")
>
> What I'm asking already happens in sequence concatenation, so:
> <#local foo=['a','b'] />
> <#local foo=foo+['c'] />
> <#list foo as k>
> ${k}
> </#list>
>
> prints:
> a b c
>
> I'm using FreeMarker ver 2.3.15
>
>
> thanks a lot!
> Ioannis
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing 
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
>
>   

-- 
Ioannis Cherouvim
Software Engineer
mail: [email protected]
web: www.eworx.gr


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.