In the HomePage.php file (or whatever page type you're wanting to iterate over data on):
class HomePage extends Page {
function UpcomingEvents($limit = 5) {
return DataObject::get('EventPage', '', 'Date DESC', '', $limit);
}
}
class HomePage_Controller extends Page_Controller {
}
In the HomePage.ss template (or respective template for your page type inside templates for your current theme):
You use <% control MyFunctionReturningADataObjectSet %> to iterate over data. DataObject::get() returns a DataObjectSet, so we can iterate over the DataObject's in the set by using <% control UpcomingEvents(5) %> in this case. You'll also note that we used (5), this means you can effectively apply a limit on the records returned from the template, which defaults to 5 if you just use <% control UpcomingEvents %> without the argument.
<% if UpcomingEvents %>
<ul class="eventList">
<% control UpcomingEvents(5) %>
<li>
<h3>$Title</h3>
<p>$Content.FirstParagraph ...<a href="$Link">read more</a></p>
</li>
<% end_control %>
</ul>
<% end_if %>
The second and third arguments to DataObject::get() are for filter, and sort respectively. And, the 5th argument is how many items you want to return, so you can effectively establish a limit of how many records to return. This means you can sort by a date, for example:
DataObject::get('EventPage', '', 'EventPage.Date DESC', '', 5);
Pagination can also be applied, if you limit a set.
Here's some useful references in the SS documentation wiki:
http://doc.silverstripe.com/doku.php?id=private:recipes:pagination
http://doc.silverstripe.com/doku.php?id=dataobjectset
http://doc.silverstripe.com/doku.php?id=templates
Hope this explains what you're after!
Sean