Hi
Here's how I solved this in a project of mine.
On the DataObject, add the following code:
private static $currMon;
public function CurrentMonth(){
$month = strftime('%B %Y', strtotime($this->Date));
if($month == self::$currMon){
return false;
} else {
self::$currMon = $month;
return utf8_encode($month);
}
}
This will return the current month (incl. year) as string whenever the date changes. Otherwise false will be returned.
Now all that's left to do is to get a list of DataObjects sorted by Date (in the following example accessed via Dates, and iterate over it with the following template code:
<% control Dates %>
<% if CurrentMonth %>
<h2>$CurrentMonth</h2>
<% end_if %>
... your markup for each item ...
<% end_control %>
For completeness sake here's how the "Dates" method could look like:
public function Dates($limit = 100){
return DataObject::get(
'DataObjectClassName',
$this->ClassName . 'ID = '. $this->ID,
'Date ASC', '', $limit
);
}
Make sure the items in red match your Item class and date field.