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

retrieving just 3 items from a datalist


Go to End


2 Posts   1268 Views

Avatar
Bruce B

Community Member, 164 Posts

13 July 2012 at 5:35pm

I have a new client that nicely coincides with the release of SS3 so I am converting the existing site from SS2.4. At one point, I want to show just the first 3 images from a gallery, rather than all the images. I'm guessing that this is a simple extension of the normal datalist syntax but I can't find it. Can someone offer a solution?

return DisplayAnythingFile::get()->filter(array('GalleryID' => $this->ImageGalleryID))->sort(array('Sort'=>'ASC'));

For extra points, I have another site where I'd like to retrieve a random 3 images from a gallery. I'm happy to just have a random starting point and retrieve the next 2 consecutive images. Any ideas?

thanks
bruce

Avatar
Bruce B

Community Member, 164 Posts

13 July 2012 at 7:45pm

When all else fails, RTFM. Or in this case, the API docs for datalist. The API lists getRange but that immediately throws an 'deprecated' message that describes the new method - limit($length,$offset). That is the answer to both my questions.

cheers all
bruce