Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

Multiple Grouping Levels in SS3


Go to End
Reply


2 Posts   606 Views

Avatar
purplespider

Community Member, 86 Posts

22 September 2012 at 6:47am

Edited: 22/09/2012 6:48am

I'm struggling to get multiple grouping levels working in SS3, it was very simple in SS2.

Basically I have a bunch of Event data objects, each with a Date & Title and I wish to display them in the template grouped by Year and then Month like so:

2012
	January
		Event X
		Event Y
	February
		Event Z

2013
	January
		Event A
		Event B

This was easy in SS2, I could just do this:

function Entries() {
	return DataObject::get("Entry");
}

<% control Entries.GroupedBy(Year) %>
	<p>$Year</p>
	
	<% control Children.GroupedBy(Month) %>
		<p>$Month</p>
		
			<% control Children %>
				<p>$EventTitle</p>
				
			<% end_control %>
	<% end_control %>
<% end_control %>

However in SS3, I'm struggling to get both groupings to work, I can get the Year grouping working, but not the Month one also. It's something to do with the new GroupedList.

Can someone please advise how I can achieve this in SS3?

Thanks!
James

Avatar
purplespider

Community Member, 86 Posts

5 December 2012 at 12:48am

Any advice on how to achieve this in SS3 would be much appreciated! :)