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.

Archive /

Our old forums are still available as a read-only archive.

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

How Can I use Google Calendar in my Site


Reply


6 Posts   3304 Views

Avatar
Singh

Community Member, 9 Posts

17 November 2008 at 9:41am

Hi,

I am new to SilverStripe and I liked its functionality to make a really nice website in a short time. I am just stuck with google calendar at the moment. I am unable to embed it into a page. I tried pasting the embedding code in HTML View, but it just won't work. Can anyone please help me.

Thanks

Avatar
Double-A-Ron

Community Member, 604 Posts

17 November 2008 at 10:14am

Edited: 17/11/2008 10:19am

Hi Singh,

TinyMCE by default strips alot of HTML from the CMS side of things. However you can change the setup of TinyMCE so that it accepts most raw html. This not an ideal solution however, as it means that any user who has access to the admin, can put any HTML markup they like on your pages, potentially throwing out your design, or possibly launching an XSS attack.

Here is a thread from a while ago where someone had the same problem trying to insert Paypal buttons HTML: [url]http://www.silverstripe.com/site-builders-forum/flat/202803[/url]. Basically the same fundamentals of what you are trying to do, although Google will be solid javascript I imagine. All the best info links on how to change TinyMCE to accept HTML are there. Take note of how this developer finally solved her problem however, as I think this is far safer.

This solution involves extending the Page and adding a method that hardcodes, and returns the HTML to the SS template. To understand more about how this works, I suggest you go through the [url=http://doc.silverstripe.com/doku.php?id=tutorials]Tutorials[/url] one by one. They will give you all the basics you need to know about extending Silverstripe this way.

Cheers
Aaron

Avatar
Singh

Community Member, 9 Posts

17 November 2008 at 10:17am

Thanks a lot Aaron,

Really appreciate your help. I will go this way and let you know, how things went.

Kind Regards.
Singh

Avatar
Double-A-Ron

Community Member, 604 Posts

17 November 2008 at 10:30am

Edited: 17/11/2008 10:33am

Here's a simple method that you can use:

Say you are just using a Page type. The code that does the work will be in /mysite/Page.php.

If you add a method to the PageController in that file that returns the HTML you require, you will be able to access that code in all of your Pages that are of this type.

Here is a simple method to get you started.

public function getGCalHTML()
{
$html = '<iframe src="http://www.google.com/calendar/embed?src=kse%40neteffects.no&title=Kalender%20for%20Kim%20Stian&height=614" style=" border-width:0 " width="640" frameborder="0" height="614"></iframe>'

return $html;
}

Then, in your Page.ss file, you simply call this method to output the html that is returned:

<div>
$getGCalHTML
</div>

Note, Div's are not required. The $getGCalHTML will output whatever it is that make that method return.

The above example is a good way for you to understand how it all works, but probably not ideal for production, as it will show your calendar on every page that is set as a normal page in your admin. You probably only want this on one page, in which case you need to create a new page type just for this (e.g. CalendarPage). The [url=http://doc.silverstripe.com/doku.php?id=tutorial:1-building-a-basic-site"]tutorial on making a custom home page[/url] is exactly what you need to look at here.

Hope that helps.
Aaron

Avatar
Singh

Community Member, 9 Posts

17 November 2008 at 10:36am

Hi Aaron,

Thanks a ton, Your first reply, did the trick. Its all working now.

Kind Regards.
Singh

Avatar
Double-A-Ron

Community Member, 604 Posts

17 November 2008 at 10:51am

Glad it helped. :-)

Just keep in mind that accepting too much html into your CMS opens doors to other potential problems. If you are the only one maintaining the site, it should be fine. But if this site is for a client or multiple content administrators, it's giving them a bit too much control over they layout.

If it were me, at the very worst, I would only mod TinyMCE to allow iframes for this problem.

But the option of extending the page, and hardcoding the HTML there is far and away the most secure option and gives you total control.

Cheers
Aaron