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

Calendar event module - upcoming events on homepage?


Go to End


36 Posts   9009 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