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

event_calendar: Upcoming Events on Startpage


Go to End


14 Posts   2866 Views

Avatar
oleze

Community Member, 65 Posts

7 May 2010 at 3:06am

Hey guys,
i have a problem with the UpcomingEvents function of the event_calendar module in SilverStripe 2.4. I'd like to display the next 5 events on the startpage in a sidebarbox. I tried using $UpcomingEvents directly and

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

which I found in another thread. Both don't work. I get some HTML with empty links:

<div id="events">
<ul id="Menu1">
<li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href=""></a></li>
<li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href=""></a></li>
<li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href=""></a></li>
<li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href=""></a></li>
</ul>
</div>

and yes, I only get four of those.
Thanks for your help.

oleze

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 May 2010 at 4:24am

It returns a dataobjectset. You can't just put $UpcomingEvents on your template. You have to loop through each event in a control.

<% control UpcomingEvents %>

Avatar
oleze

Community Member, 65 Posts

7 May 2010 at 5:41am

Okay, dummy fault...
So now I get no events (but there are).

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 May 2010 at 5:59am

Post your code?

Avatar
oleze

Community Member, 65 Posts

7 May 2010 at 7:34am

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

and

<div id="events">
<% control UpcomingEvents %>
$UpcomingEvents
<% end_control %>
</div>

Output is just the <div>

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 May 2010 at 8:11am

You need to loop through the events.. It works just like any other control block.

<ul>
<% control UpcomingEvents %>
<li>$_Dates : $Event.Title</li>
<% end_control %>
</ul>

Avatar
oleze

Community Member, 65 Posts

8 May 2010 at 11:26am

Okay, that makes sense when using control. I'm using Image Gallery's RecentImages function and that works without control but the control-element makes styling much more flexible.

Thank you for your help.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 May 2010 at 12:09pm

I struggled with the $RecentImageGallery function. That's a pretty bad breech of the MVC pattern do bundle that much markup into a single template variable, but ultimately I decided it was worth it due to all the Javascript and CSS dependencies with the popup plugins.

Glad you got it working, though!

Go to Top