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.

General Questions /

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

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

retrieving just 3 items from a datalist


Reply


2 Posts   699 Views

Avatar
Bruce B

Community Member, 145 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, 145 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