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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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