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.

Customising the CMS /

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

Adding content to each page


Go to End


3 Posts   1333 Views

Avatar
barryvanveen

Community Member, 11 Posts

18 May 2010 at 8:45am

Hi all,

I've only started developing with Silverstripe a short while ago and got some questions. I want to include a list of upcoming events from a Google Calendar. I started by making a widget because I found the "how to make your own widget" tutorial. Now that I'm done, and the widget is working, I think it is not exactly what I need :-)

The list of events should be on every page, or at least at almost every page. Using a widget doesn't seem natural because one has to use the widget-tab to add it to each page.

Then I thought I could just add a method to the Page class using this piece of code:

class Page_Controller extends ContentController {
...
  function Events() {
    $oGCalendarWidget = new GCalendarWidget();
    return $oGCalendarWidget->Events();
  }  
...
}

From what I understood this would make it accessible in the templates using <% control Events %>, but I don't get any results. Is this the correct way to do this kind of stuff?

Cheers,

Barry

Avatar
_Vince

Community Member, 165 Posts

18 May 2010 at 10:36am

The <% control Events %> calls the function but you still need to display the results on the template.

Are you doing that? it should be something like

<% control Events %>
<div class="EventName">$EventName</div>
<div class="EventDate">$EventDate</div>
<% end_control %>

and so on.

Avatar
barryvanveen

Community Member, 11 Posts

23 May 2010 at 12:34pm

Sorry for the late response. My problem has been (partially) solved. I was expecting it all to work because the widget worked, but I didnt't realise that this function would not use the widget-template. So now everythings works perfectly but is still don't know if this is "the right way" to solve it.

I've got this library (Zend_Gdata) which is the google api I use, and I've got a class that has all the needed functionality. Where should you normally put those files in your sites hierarchy? Should I put the Calendar-class in mysite/code (seems the natural place) and where should i keep the library?

Cheers

Barry