I have a model where one field is a date. I want to display elements from that model, grouped by year and by month, like this:
== 2013 ==
=== April ===
* Ele
A simple solution which have not been added here properly is this:
For year and month grouping, add the fields as Transient to your model:
...
/**
* @var int
* @transient
*/
protected $year;
/**
* @var int
* @transient
*/
protected $month;
/**
* @return int
*/
public function getYear()
{
if (!$this->year) {
$this->year = $this->getDateTimeField()->format('Y');
}
return $this->year;
}
/**
* @return int
*/
public function getMonth()
{
if (!this->month) {
$this->month = $this->getDateTimeField('n');
}
return $this->month;
}
Then in the template:
...