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.

Customising the CMS /

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

Get a custom collection from a page retrieved with DataObject::get


Go to End


2 Posts   1352 Views

Avatar
nomadic

Community Member, 2 Posts

1 September 2013 at 4:54am

I have a collection of images within a custom page class, that represents a project and its associated images.

For the front page - I would like to show the first image from each project within a slider. The only issue I have is how to get to the images!

I started with this code in the controller :

	public function ProjectPageList($limit=6){
		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
		$list = DataObject::get("ProjectPage", "", "Created DESC","","$start , $limit");
		return $list;
	}

And then in the view:
<% loop ProjectPageList %>
	<li>
		<a href="$Link">
		<% control getGalleryImages(1) %>  
        	<img src="$Image" alt="$Title" />
        <% end_control %>
		</a>
		<a class="inspiration" href="/your-inspiration/"><div>See more inspiration</div></a>
		<a class="viewkitchen" href="$Link"><div>View this kitchen</div></a>
	</li>	
<% end_loop %>

A shove in the right direction would be appreciated!

Avatar
Willr

Forum Moderator, 5523 Posts

7 September 2013 at 2:25pm

How have you linked to the images in your DataModel? Do you have a relation (like a $has_many) to the images?

If that is the case then the ORM handles all the queries for you and you can just include <% loop Images %>.. in your template.