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

event_calendar: Upcoming Events on Startpage


Go to End
Reply

14 Posts   1891 Views

Avatar
oleze

7 May 2010 at 3:06am Community Member, 65 Posts

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

7 May 2010 at 4:24am 4085 Posts

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

7 May 2010 at 5:41am Community Member, 65 Posts

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

Avatar
UncleCheese

7 May 2010 at 5:59am 4085 Posts

Post your code?

Avatar
oleze

7 May 2010 at 7:34am Community Member, 65 Posts

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

7 May 2010 at 8:11am 4085 Posts

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

8 May 2010 at 11:26am Community Member, 65 Posts

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

8 May 2010 at 12:09pm 4085 Posts

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