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

Force Calendar Widget to use specific Events


Go to End


7 Posts   1873 Views

Avatar
staylor

Community Member, 7 Posts

28 September 2009 at 2:55pm

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!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

28 September 2009 at 3:28pm

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?

Avatar
staylor

Community Member, 7 Posts

28 September 2009 at 3:37pm

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.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

28 September 2009 at 5:13pm

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

Avatar
staylor

Community Member, 7 Posts

29 September 2009 at 7:05am

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

29 September 2009 at 7:30am

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.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

29 September 2009 at 7:33am

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