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.

All other Modules /

Discuss all other Modules here.

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

Event Calendar - Past Events


Go to End


5 Posts   1690 Views

Avatar
bod

Community Member, 72 Posts

13 April 2010 at 7:47am

Edited: 13/04/2010 7:51am

Hi, Does anyone know how to show past events from the Event Calendar?

I know there's the upcomingEvent function but is there a past/previous event function? I want to show a list of past event teasers on the homepage, yesterday and back - my current code

	 function Events() {
		 $today = date("Y-m-d");
		 return DataObject::get_one("Calendar")->Events(null, $today, null, false, 5, null);
		 }

just shows all upcoming events and trying something like

<% control PreviousEvents %>
$Event.Title $_Dates $Event.Link, etc..
<% end_control %>

gives no joy either,

..any ideas?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 April 2010 at 8:32am

I believe the function RecentEvents() is decorated into your SiteTree.

Avatar
bod

Community Member, 72 Posts

13 April 2010 at 9:08am

No joy with

	 function RecentEvents() {
		 $today = date("Y-m-d");
		 return DataObject::get_one("Calendar")->RecentEvents(null, $today, null, false, 5, null);
		 }

and this in the .ss file
   <% if RecentEvents %>
	
		<% control RecentEvents %>
			<dl class="diary-events">
      <dt>$_Dates</dt>
      <dd><h4 class="summary"><% if Announcement %><a href="$Link">$RecentEventsTitle</a><% else %><a href="$Link">$RecentEventsTitle</a><% end_if %></h4>
			
      <% if Announcement %>
      $Content
      <% else %>
      <% control RecentEvents %>$Content.LimitWordCount(60)<% end_control %> <a href="$Link"><% _t('MORE','more...') %></a>
      <% end_if %>
      <br />
      <% if Announcement %><a href="$Link">Read More&#8230;</a><% else %><a href="$Link">Read More&#8230;</a><% end_if %>
		</dd>
    </dl>	
		<% end_control %>

Sent you an email over the weekend so best wait till I hear back from you re: this with the other stuff.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 April 2010 at 9:16am

Oh, this is Adam? Hey, there.. Will get back to you tonight.

You shouldn't have to write a function. The RecentEvents() function is decorated on your SiteTree class, just like UpcomingEvents. The first argument is the number of events to show (default is 5), and the second is a url-segment to the calendar you want to draw from. If null, it gets the first Calendar it finds in the DB. For sites with one calendar, you can usually just leave those both empty.

So delete any functions you've written, and just let the core function do its thing. You should be able to call <% control RecentEvents %> on any SiteTree subclass.

Avatar
bod

Community Member, 72 Posts

13 April 2010 at 9:43am

:o) Yep tis me, UC, had a footle with that but my mojo is obviously not working tonight, no worries, catch up with you later ;o) ta!