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.

Blog Module

Discuss the Blog Module.

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

Heading for Archive View


Reply

3 Posts   1135 Views

Avatar
jdj

16 July 2009 at 4:52pm Community Member, 3 Posts

In the BlogHolder template, there is conditional to display the page title or to change this if viewing tabs:

<% if Tag %>
   <h1><% _t('VIEWINGTAGGED', 'Viewing entries tagged with') %> '$Tag'</h1>
<% else %>
<h1>$Title</h1>
<% end_if %>

Is there a way to do this for archives by date? I haven't found anything in the docs.

Avatar
Juanitou

23 July 2009 at 1:05am Community Member, 323 Posts

Hi! You're not alone I'm also trying to do it. Hope someone helps!

Avatar
Juanitou

23 July 2009 at 2:12am (Last edited: 23 July 2009 2:36am), Community Member, 323 Posts

I found it!

In BlogHolder_Controller:

function archive() {
   if(is_numeric(Director::urlParam('Action'))) {
      $year = Director::urlParam('Action');
      $month = Director::urlParam('ID');

      if($month && is_numeric($month) && $month >= 1 && $month <= 12 && is_numeric($year)) {
         $date = new Date('Date');
         $date->setValue(array(
            'Day' => 1,
            'Month' => $month,
            'Year' => $year
         ));
         $output =new DataObjectSet();
         $output->push(new ArrayData(array(
            'Date' => $date
         )));
         return $output;
      } else if(is_numeric($year)) {
         $date = new Date('Date');
         $date->setValue(array(
            'Day' => 1,
            'Month' => 1,
            'Year' => $year
         ));
         $output =new DataObjectSet();
         $output->push(new ArrayData(array(
            'Date' => $date->Year()
         )));
         return $output;
      } else {
         return array();
      }
   }
}

Then in BlogHolder.ss:

…
<% if archive %>
<% control Archive %>
   <h3 id="ViewingArchived"><% _t('VIEWINGARCHIVED', 'Viewing entries published on') %> <% if Date.Month %>$Date.FormatI18N(%B %Y)<% else %>$Date<% end_if %></h3>
<% end_control %>
<% end_if %>
…

Don't ask me why it is necessary to use a DataObjectSet instead of a simple array: the latter didn't worked. I'm sure there's a lighter and smarter way to do it.

Regards,
Juan