Re: Looping over a List

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Monday, June 15, 2009, 5:59:23 PM, jpcook wrote:
>
> Hello,
>
> Is it possible to use the item_index value to retrieve a specific value from
> a list. eg)
>
> <#list resource.fixtures as fixtures>                           
>         <#if
> fixtures[fixtures_index+1].competition.name.abbrTextLong !=
> fixtures[fixtures_index].competition.name.abbrTextLong >
>                 <div
> class="compName">${fixtures.competition.name.abbrTextLong}</div>   
>         </#if>
> </#list>
>
> The above does not work, fixtures is a standard java ArrayList.

I guess you wanted to write "resources.fixtures[fixtures_index+1]"
instead of "fixtures[fixtures_index+1]", and just "fixtures" instead
of "fixtures[fixtures_index]". Then also you may want to change "as
fixtures" to "as fixture", and then it will be less confusing.

> Basically what I am trying to do is compare some properties on the next
> value in the list with the current value and if they aren't the same i wan't
> to display a header.
>
> It seems like #list is more like a  for each loop and there doesn't seem an
> obvious way to do this?

#list is the same as a for-each loop, only with some extra variables
(like ..._index).

> Thanks
> Jonathan

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
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
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.