Jump to:

10929 Posts in 2613 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Force Calendar Widget to use specific Events

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1177 Views
  • staylor
    Avatar
    Community Member
    7 Posts

    Force Calendar Widget to use specific Events Link to this post

    Hi there,

    I've done something weird with your calendar, and moved it outside the calendars template and on to the main side bar template. This seems to be working fine, aside from the calendar links going to whatever the last event page you are at was..

    My question is how do I force the calendar widget to use a specific event collection across all pages? I tried modifying a bit of the php code around where the "default view" was set but not really having much luck.

    I was wondering if there is a place I can set this that would override and be used globally?

    Thanks!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Force Calendar Widget to use specific Events Link to this post

    I'm sorry. I'm having really hard time understanding what you're trying to do. Could you try to explain it a little better? Maybe some screenshots, or better yet a link?

  • staylor
    Avatar
    Community Member
    7 Posts

    Re: Force Calendar Widget to use specific Events Link to this post

    Yeah, sure sorry..

    With the Event module, you have a Calendar page and Calendar Event page..

    The problem is if I have 2 calendar pages (I actually have 3). My calendar widget which I've taken out of the main calendar template and put in the site template in sidebar switches the link based on what Calendar page you are viewing, and in all usual circumstances this is correct. However, my requirement is that the calendar ONLY links to the 'Events' calendar and it should not matter where in the page you are.

    I'm guessing in a usual scenario, you'd have a Calendar, then Calendar Event pages, however, it doesn't seperate like the client requires and I need that distinguished separation to the events, but they still like the calendar.

    So what typically is happening: I go to website, page calendar on template links to proper Events page, I click on date, go to event date page, the other Calendar pages are subpages, so I click on one of those to view them, then I navigate back to the index page, and the calendar links to whatever Calendar page I visited last.

    So in essence, I was thinking the tinkering may lay along these lines:

       public function CalendarWidget()
       {
          return new CalendarWidget($this, $this->start_date, $this->end_date, ($this->view == "default"));
       }

    To something like

       public function CalendarWidget()
       {
          return new CalendarWidget($this, $this->start_date, $this->end_date, ($this->view == "Events"));
       }
       
    But that doesn't work...

    I'd message you the site name, but it's a non profit org and I'm not sure we have permission to use all the pictures on the site yet, so I'm hesitant at making a public link. If you have an email, I can send you the link there.

    Thanks.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Force Calendar Widget to use specific Events Link to this post

    Well, the calendar widgets are decorated into your sitetree, so for any given page, you can just use $CalendarWidget or $LiveCalendarWidget. If you have multiple calendars, you can pass it the url segment of the calendar page you want to control that widget. So in theory, if every calendar widget has to link to the same calendar, regardless of what the current controller is, you could just create a custom function. This assumes, of course, that you've subclassed all your calendar pages.

    MyCalendar.php

    function SpecialCalendarWidget()
    {
    // Not sure about this. If it doesn't work, there are other ways
    return CalendarSiteTree::CalendarWidget("some-special-urlsegment");
    }

    MyCalendar.ss

    $SpecialCalendarWidget

    MyCalendarEvent.ss

    $SpecialCalendarWidget

  • staylor
    Avatar
    Community Member
    7 Posts

    Re: Force Calendar Widget to use specific Events Link to this post

    So if I understand you correctly if I create a MyCalendar.php file in mysite/code and have ti say..

    <?php

    function SpecialCalendarWidget()
    {
    // Not sure about this. If it doesn't work, there are other ways
    return CalendarSiteTree::CalendarWidget("events");
    }

    ?>

    And that would always set the calendar to take you to the Events calendar?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Force Calendar Widget to use specific Events Link to this post

    Yes. You can actually save yourself some trouble and just put that function in Page_Controller, which will make it globally accessible. Then just create new templates for Calendar.ss and CalendarEvent.ss in your theme dir, and change all $CalendarWidget calls to $MyCalendarWidget.. or whatever you call it.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Force Calendar Widget to use specific Events Link to this post

    So, in summation,

    Page.php

    Page_Controller extends Content_Controller
    {
    function MyCalendarWidget()
    {
    return CalendarSiteTree::CalendarWidget("some-special-urlsegment");
    }
    }

    /my-theme-dir/templates/Layout/Calendar.ss
    $MyCalendarWidget

    /my-theme-dir/templates/Layout/CalendarEvent.ss
    $MyCalendarWidget

    1177 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.