Jump to:

10386 Posts in 2198 Topics by 1712 members

All other Modules

SilverStripe Forums » All other Modules » EventCalendar 3 - Loading announcements with UpcomingEvents()

Discuss all other Modules here.

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 223 Views
  • cmc
    Avatar
    Community Member
    18 Posts

    EventCalendar 3 - Loading announcements with UpcomingEvents() Link to this post

    I'm trying to show upcoming events, including announcements, on a home page. I've found a few old threads about this, but those solutions no longer work. For one thing is_announcement is no longer a field in the CalendarDateTime table. It looks like the UpcomingEvents function in Events Calendar 3 should grab announcements by default, but I'm not getting any.

    Also, $EventTitle and $_Dates no longer work in templates. $Title and $DateRange are working for me in their place.

    As far as pulling announcements, I've got the first function below in my Page_Controller class. It works for pulling events, but not announcements.

    public function MyUpcomingEvents($numEvents=5) {
       return DataObject::get_one("Calendar")->upcomingEvents($numEvents, );
       }

    I tried this version from the older threads. It throws an error and the page won't load at all.

    public function MyUpcomingEvents($numEvents=5) {
       return DataObject::get_one("Calendar")->upcomingEvents($numEvents, "is_announcements = 1");
    }

    This version does the same as the first, loads events only, no announcements.

    public function MyUpcomingEvents($numEvents=5) {
          return DataObject::get_one("Calendar")->upcomingEvents($numEvents, "(CalendarDateTime.ClassName LIKE 'CalendarAnnouncement' OR CalendarDateTime.ClassName LIKE 'CalendarDateTime')");
    }

    This is what I have in my HomePage.ss

    <% control MyUpcomingEvents(5) %>
    <% if Event %>
    $DateRange
    <a href="{$Link}" title="More Details about {$Title}">$Title</a>
    <% end_if %>
    <% end_control %>

    Any ideas how I can get announcements ?

    Thanks,
    Cathy

  • cmc
    Avatar
    Community Member
    18 Posts

    Re: EventCalendar 3 - Loading announcements with UpcomingEvents() Link to this post

    Thanks to Bstarr in this thread -
    http://www.silverstripe.org/all-other-modules/show/17306

    I changed the code in the HomePage.ss template to the following and the first function is now working.

    <% if Announcement %>
    $DateRange
    <a href="{$Link}" title="More Details about {$Title}">$Title</a>
    <% else %>
    <% if Event %>
    $DateRange
    <a href="{$Event.Link}" title="More Details about {$Event.Title}">$Event.Title</a>
    <% else %>
    No events to display
    <% end_if %>
    <% end_if %>

    223 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.