Jump to:

23358 Posts in 17875 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » retrieving just 3 items from a datalist

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

Page: 1
Go to End
Author Topic: 657 Views
  • Bruce B
    Avatar
    Community Member
    145 Posts

    retrieving just 3 items from a datalist Link to this post

    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

  • Bruce B
    Avatar
    Community Member
    145 Posts

    Re: retrieving just 3 items from a datalist Link to this post

    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

    657 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.