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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

Calendar event module - upcoming events on homepage?


Go to End


36 Posts   7950 Views

Avatar
FireMe!

Community Member, 74 Posts

16 March 2009 at 4:51am

Edited: 16/03/2009 4:52am

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

Forum Moderator, 4102 Posts

16 March 2009 at 6:44am

$myCalendar->upcomingEvents(5);

Avatar
FireMe!

Community Member, 74 Posts

16 March 2009 at 6:51am

where would i put this?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 March 2009 at 6:58am

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!

Community Member, 74 Posts

16 March 2009 at 7:16am

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

Forum Moderator, 4102 Posts

16 March 2009 at 7:21am

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!

Community Member, 74 Posts

16 March 2009 at 7:41am

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

Forum Moderator, 4102 Posts

16 March 2009 at 8:05am

$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