Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Heading for Archive View

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1122 Views
  • jdj
    Avatar
    Community Member
    3 Posts

    Heading for Archive View Link to this post

    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.

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Heading for Archive View Link to this post

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

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Heading for Archive View Link to this post

    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

    1122 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.