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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Limit Control??**SOLVED**

Go to End

4 Posts   1768 Views


Community Member, 130 Posts

23 April 2013 at 1:29am

Edited: 23/04/2013 4:19am

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>
          <% 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


Community Member, 130 Posts

23 April 2013 at 7:40pm

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 :(


Community Member, 55 Posts

30 April 2013 at 7:28am


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



Community Member, 130 Posts

1 May 2013 at 9:44pm

Thank you Darren,
I had some help from IOTI here

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;