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

Embarassingly simple question re. Event Calendar


Go to End


6 Posts   1380 Views

Avatar
Ian Dav

Community Member, 2 Posts

13 May 2010 at 11:57pm

Hi there,

I'm sure this is something incredibly easy to do, but for some reason I can't get my head round it...

All I want to do is list back the latest 3 events from the Event Calendar module on the site homepage. Doesn't need anything fancy - just:

[Date] [Event/Announcement title] [Link to event] .... much as you would to bring back "latest news" headlines from a news section.

I'm the first to hold my hands up and say I'm not the greatest PHP-er in the world, but I think I'm probably over-complicating things here in looking for a solution. Either that or my brain is fried from deadlines and I can't see the wood for the trees...

Is there a function I can define in my HomePage.php that will enable me to do such a thing?

Hoping someone can help :)

Avatar
UncleCheese

Forum Moderator, 4102 Posts

14 May 2010 at 1:56am

Absolutely. On any page, you can use <% control UpcomingEvents(number) %>

If no number is provided, it defaults to 5 events. If you have multiple calendars, you can supply the URLSegment of the calendar you want to draw from as the second argument.

<% control UpcomingEvents(3) %>
<li>$_Dates $EventTitle $Link</li>
<% end_control %>

Avatar
UncleCheese

Forum Moderator, 4102 Posts

14 May 2010 at 1:56am

Absolutely. On any page, you can use <% control UpcomingEvents(number) %>

If no number is provided, it defaults to 5 events. If you have multiple calendars, you can supply the URLSegment of the calendar you want to draw from as the second argument.

<% control UpcomingEvents(3) %>
<li>$_Dates $EventTitle $Link</li>
<% end_control %>

Avatar
Ian Dav

Community Member, 2 Posts

14 May 2010 at 2:13am

Fantastic stuff! I knew it would be something simple :)

Tried, tested and successful. Thanks for your help Uncle C

Avatar
NickJacobs

Community Member, 148 Posts

21 July 2010 at 11:52pm

Is there any way of passing date filters to UpcomingEvents (or other built in functions) for pages away from the actual calendar template?

ie, I have a page template which lists a print ready version of Calendar Events in a specific format. What I really need to be able to do is start the page off (on first view) with all the currents months events, then let the user select which month they can print , either with calendarwidget or something like the MonthNavigator..

any ideas??

Avatar
UncleCheese

Forum Moderator, 4102 Posts

22 July 2010 at 1:09pm

Hey, Nick,

All of the key functions in the Calendar class are publicly accessible. You just have to make sure you get an instance first. Some of the most common functions are decorated into the SiteTree (e.g. UpcomingEvents()), which just automatically get a Calendar instance for you, based on URL segment, or most commonly, the only one you have in your SiteTree.

So you can write a custom function of your liking, and as long as you get something like:

$calendar = DataObject::get_one("Calendar" .... );

You can return:

$calendar->Events($filter = null, $start_date = null, $end_date = null, $default_view = false, $limit = null, $announcement_filter = null)