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.

Data Model Questions /

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

control ImageResources, how to return ImageResources in groups of 5


Go to End


3 Posts   1132 Views

Avatar
DsX

Community Member, 178 Posts

21 November 2010 at 10:06am

Edited: 21/11/2010 10:18am

Ok, I am working on a basic gallery.

I have a galleryholder, gallerypage, and the gallerypage has many ImageResources
when in the gallerypage.ss how can I control through the ImageResources but have groups of 5 ImageResources returned until all are returned? Or until a set number are returned?

I need to wrap every 5 in a div tag for use in a scroller.
the post here: http://www.silverstripe.org/data-model-questions/show/4871
explains my issue very well except for he had control over the number of segments. I may need two divs or 10.
So having a method for each isn't working (a have done this for a latestgalleries feature, since I know I have a minimum amount of data I am just calling the last 10 galleries).

I have found information on pagination thats going in the right direction, but I haven't been able to make the jump to getting a version to work for my purposes.

Avatar
DsX

Community Member, 178 Posts

21 November 2010 at 12:33pm

Ok the approach I think I would like to take is:

1: create a method (getGalleryGroupData) that can get my dataobjects (DataObject::get) and then setup and array to be returned as a dataobject so that I can loop through it in a control in the template. The array should contain 1 set of data for every group (the number of items it the group should be set by passed int) the data will simply be the limit points for querying this data.

2: a second method (getGalleryGroup) that takes two parameters and queries the for a dataobjectset and returns it.

so I should be able to use it like such in the template:

<% control GalleryGroupData %>
<div class="gallerygroup">
<% control GalleryGroup(startpoint,endpoint) %>
<img src="$galleryThumbnailURL">
$galleryDescription
<% end_control %>
<div/>
<% end_control %>

So I have the second method working already... I am lost in how I can gather the necessary information from the first dataobjectset and return it so that I can control through it.

Avatar
DsX

Community Member, 178 Posts

23 November 2010 at 6:29am

OK, played around and now know that I can't pass parameters from a template as variables.

I have a solution, will try to clean it up and get it posted.