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.

Data Model Questions /

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

DayOfMonth not working in GroupedList


Go to End


2 Posts   1142 Views

Avatar
quanto

Community Member, 91 Posts

18 April 2013 at 1:15am

Hi,

I'm trying to format a date ($Datum) in a proper way, after grouping by Datum. However, it's not formatting (not .DayOfMonth, FormatI18N or .Year).

My code:
AgendaItem.php

<?php
  class AgendaItem extends DataObject{
    static $db = array(
     ...
      'Datum' => 'Date',
      ...
    );
    
    static $has_one = array(
      'Agenda'=>'Agenda'
    );
        
    public static $default_sort='Datum';
    
    function getCMSFields() { 
      $fields = new FieldList( 
        ...
        $dateField = new DateField('Datum', 'Datum'), 
        ...
      ); 
      $dateField->setConfig('showcalendar', true); 
      $dateField->setConfig('dateformat','dd-MM-yyyy');
      return $fields; 
    } 
    
  }
?>

Agenda.php

<?php
class Agenda extends Page {
  public static $has_many = array(
    'AgendaItems' => 'AgendaItem'
  );
  
  ...

}
class Agenda_Controller extends Page_Controller {
	...
  public function getAgendaView(){
    $datums = GroupedList::create(AgendaItem::get()->sort('Datum', 'Asc'));
    return $datums;
  }
}

Agenda.ss

...
<% if getAgendaView %>
          <% loop AgendaView.GroupedBy(Datum) %> 
          <h2>
              $Datum.Nice <== not working
              $Datum.DayOfMonth  <== not working
              $Datum.FormatI18N('%B')  <== not working
              $Datum.Year  <== not working
              $Datum <== works!
            </h2>
            <% loop Children %> 
              <div id="agen$ID">
                <div class="tijd">$Tijd</div>
                <div class="titel"><a href="javascript:void(0);" onclick="showhide($ID);">$Titel</a></div>
              </div>
            <% end_loop %>
          <% end_loop %>
        <% end_if %>
...

anyone?

Avatar
quanto

Community Member, 91 Posts

27 April 2013 at 1:20am

I fixed it by editing Agenda.ss:


... 
<% if getAgendaView %> 
<% loop AgendaView.GroupedBy(Datum) %> 

<% loop Children %> 
<% if First %>
<h2> $Datum.Nice</h2> 
<% end_if %>
...
<% end_loop %> 
<% end_loop %> 
<% end_if %>