Re: Looping over a List

"Newman, John W" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <D688C4D318A63D4290AA94A33E06F7D201C7843D1B@msxmbxnsprd14.acct.upmchs.net>
What you have already should work, you're just going out of bounds by not checking if fixtures_index + 1 is still less than fixtures?size.

You can also use the range .. operator.  There is also the fixture_has_next loop variable you could use to check the bounds.  Lots of different ways to do this really..

Here's one (untested):
[#assign fixtures = resource.fixtures /]
[#assign n = fixtures?size - 1 /]
[#list 0..n as i]
	[#assign fixture = fixtures[i] /]
	[#if i == 0 || previousFixture.competition.name.abbrTextLong != fixture.competition.name.abbrTextLong]
		<div class="compName">${fixture.competition.name.abbrTextLong}</div>
	[/#if]
	[#assign previousFixture = fixture /]
[/#list]

-----Original Message-----
From: jpcook [mailto:[email protected]] 
Sent: Monday, June 15, 2009 11:59 AM
To: [email protected]
Subject: [FreeMarker-user] Looping over a List


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.

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?

Thanks
Jonathan
-- 
View this message in context: http://www.nabble.com/Looping-over-a-List-tp24037452p24037452.html
Sent from the freemarker-user mailing list archive at Nabble.com.


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

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