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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Returning data grouped by value [SOLVED]


Go to End


3 Posts   1584 Views

Avatar
LesC

Community Member, 70 Posts

2 November 2009 at 1:23am

Edited: 02/11/2009 10:15pm

I've got a bunch of dataobjects (lets call them Events) that each have a related category (EventCategory) and I'd like to return these to the template view so that I could show the events listed by category, something like:

Category 1 title
Event name
Event name

Category 2 title
Event name

Category 3 title
Event name
Event name

How would I go about doing this, so that I can have a dynamic amount of categories (a category will always have events too)?

Avatar
Howard

Community Member, 215 Posts

2 November 2009 at 7:16am

I recently had the same question and the way that I got around it was to use the NestedDataObjectManager, this allowed each page to has_many categories then each category to has_many objects. This way you could add many categories to each page as needed then add the objects to those categories. In the template it was then as simple as:

<% control Categories %>
$CategoryTitle
<% control Events %>
$EventTitle - $Description
<% end_control %>
<% end_control %>

Avatar
LesC

Community Member, 70 Posts

2 November 2009 at 10:15pm

Thanks Howard, I worked it out just as you posted that one!

Cheers