Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Limit Control??**SOLVED**

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 863 Views
  • ambient
    Avatar
    Community Member
    123 Posts

    Limit Control??**SOLVED** Link to this post

    Hi All,

    I have a gallery which I am using DataObject Manager to add multiple images and it all works fine.

    However I want to display the first 3 images of the gallery on another page.

    I've searched for a solution and tried figuring it out myself but have had no success.

    I can get the images to appear on the other page but it shows all of them instead of just 3.

    This is my code that I have tried

    <% if GalleryImages %>
       <% control GalleryImages(3) %>
    <div class="listing_pic">
             <a href="$Link"><img src="$MyGalleryImage.GroupThumb.URL" alt="<% sprintf(_t("IMAGE","%s image"),$Title) %>" /></a>
    </div>
    <% end_control %>
    <% end_if %>

    I also have tried

    public function GalleryImages($Limit = 3){

    return DataObject::get("GalleryImage", "ParentID = $this->ID", Null, Null, $Limit);

    }

    Any help would be appreciated, Thanks

    ** EDIT - I am using ss 2.4

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Limit Control??**SOLVED** Link to this post

    Nobody has any ideas on this?

    I thought it would be straightforward enough to do but just haven't figured out what I'm doing wrong

  • Dazman1
    Avatar
    Community Member
    30 Posts

    Re: Limit Control??**SOLVED** Link to this post

    Hi

    Maybe try this

    function NewestGalleryImages($num=3) {
    $GalleryImages = DataObject::get_one("GalleryImage");
          
          return ($GalleryImages) ? DataObject::get("GalleryImage", "", "ParentID = $this->ID", "", $num) : false;

    let me know

    Darren

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Limit Control??**SOLVED** Link to this post

    Thank you Darren,
    I had some help from IOTI here http://www.silverstripe.org/general-questions/show/23540#post321545

    And this got it working in the end

    public function GImages($limit = 3){
    $filter = 'BelongToProductID =' . $this->ID; //filter
    if($images = DataObject::get('GalleryImage', $filter, $sort='', $join='', $limit="0,$limit")){
    return $images;
    }
    }

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