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:

General Questions /

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

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

Iterate through $has_many items


Go to End


3 Posts   1125 Views

Avatar
MartinPhone

Community Member, 57 Posts

12 February 2012 at 3:54am

Edited: 12/02/2012 3:55am

Just wanted to confirm,

There isn't (currently?) a way to access every item of a 'normal' SS data type (image, text, etc) I've got in a $has_many in my page? Like I would with a <% control %>?

(I have a bunch of images I want to access but don't really feel like I should have to create a new object just to fill it with a single piece of data...)

I've seen this http://www.silverstripe.org/archive/show/408 but it is quite old, might not be exactly the same as what I want and maybe something's changed!

Just want to find the simplest solution to what I think must be a simple problem!

Avatar
Willr

Forum Moderator, 5523 Posts

12 February 2012 at 8:29pm

Edited: 29/03/2012 8:30pm

You can use a <% control %> statement (or <% loop %> in SS3.0) to iterate over a has_many. Has_many relationships are ComponentSets.

http://api.silverstripe.org/2.4/sapphire/model/ComponentSet.html

Avatar
MartinPhone

Community Member, 57 Posts

29 March 2012 at 9:47am

Wheee! Excellent news! Thanks.