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.

All other Modules /

Discuss all other Modules here.

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

Embarassingly simple question re. Event Calendar


Reply


6 Posts   1005 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, 4092 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, 4092 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, 144 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, 4092 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)