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

Calendar event module - upcoming events on homepage?


Go to End
Reply

36 Posts   5963 Views

Avatar
FireMe!

16 March 2009 at 4:51am (Last edited: 16 March 2009 4:52am), Community Member, 74 Posts

Hi

Its fireme asking for help again lol, Ok i have the calendar event module and would like to have next 5 upcoming event on the home page. the same as i got the top 5 latest news articles. But as im not a php guru, i dont know how to do it. So as you are all very nice and helpful i thought i would ask here.

Thanks in advance

FireMe!

Avatar
UncleCheese

16 March 2009 at 6:44am 4085 Posts

$myCalendar->upcomingEvents(5);

Avatar
FireMe!

16 March 2009 at 6:51am Community Member, 74 Posts

where would i put this?

Avatar
UncleCheese

16 March 2009 at 6:58am 4085 Posts

In your homepage controller.

function UpcomingEvents()
{
return DataObject::get_one("Calendar")->upcomingEvents(5);
}

<% control UpcomingEvents %>
<h3>$_Dates</h3>
<h4><a href=$Event.Link">$Event.Title</a></h4>
<% end_control %>

Avatar
FireMe!

16 March 2009 at 7:16am Community Member, 74 Posts

Thanks that worked great, is there also a way if the latest event is in the past to still display as upcoming?, see i dont want a blank part of the home page if there is no upcoming events. if you get what i mean??

Thanks in advance

Avatar
UncleCheese

16 March 2009 at 7:21am 4085 Posts

There should be a recentEvents() function, as well. Try it. If not, I'll add it in.

Also, FYI, the second argument of those functions is a filter in case you want to do something like upcomingEvents(5, "Category = 'Blah')

Avatar
FireMe!

16 March 2009 at 7:41am Community Member, 74 Posts

i tried the following but didn't seem to work.

function RecentEvents()
{
return DataObject::get_one("Calendar")->RecentEvents(5);
}

also i am trying to format the date, the same as i did for my latest news

<div class="month">$Date.Format(M)</div>

<div class="day">$Date.Format(d)</div>

i have tried

<div class="month">$_Dates.Format(M)</div>

<div class="day">$_Dates.Format(d)</div>

but does not work and i get

Fatal error: Call to a member function XML_val() on a non-object

Avatar
UncleCheese

16 March 2009 at 8:05am 4085 Posts

$StartDate and $EndDate are the properties you're looking for. $_Dates is a magic method that returns a human readable date range (e.g. October 10-20, 2009) in microformat compliant markup.

Go to Top