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.

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   803 Views


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 %>
		<a href="$Link">
		<% control getGalleryImages(1) %>  
        	<img src="$Image" alt="$Title" />
        <% end_control %>
		<a class="inspiration" href="/your-inspiration/"><div>See more inspiration</div></a>
		<a class="viewkitchen" href="$Link"><div>View this kitchen</div></a>
<% end_loop %>

A shove in the right direction would be appreciated!


Forum Moderator, 5522 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.