1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » Heading for Archive View
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 915 Views |
-
Heading for Archive View

16 July 2009 at 4:52pm
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.
-
Re: Heading for Archive View

23 July 2009 at 1:05am
Hi! You're not alone I'm also trying to do it. Hope someone helps!
-
Re: Heading for Archive View

23 July 2009 at 2:12am Last edited: 23 July 2009 2:36am
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
| 915 Views | ||
|
Page:
1
|
Go to Top |

