Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How Can I use Google Calendar in my Site

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

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

Page: 1
Go to End
Author Topic: 3232 Views
  • Singh
    Avatar
    Community Member
    9 Posts

    How Can I use Google Calendar in my Site Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: How Can I use Google Calendar in my Site Link to this post

    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: http://www.silverstripe.com/site-builders-forum/flat/202803. 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 Tutorials one by one. They will give you all the basics you need to know about extending Silverstripe this way.

    Cheers
    Aaron

  • Singh
    Avatar
    Community Member
    9 Posts

    Re: How Can I use Google Calendar in my Site Link to this post

    Thanks a lot Aaron,

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

    Kind Regards.
    Singh

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: How Can I use Google Calendar in my Site Link to this post

    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 tutorial on making a custom home page is exactly what you need to look at here.

    Hope that helps.
    Aaron

  • Singh
    Avatar
    Community Member
    9 Posts

    Re: How Can I use Google Calendar in my Site Link to this post

    Hi Aaron,

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

    Kind Regards.
    Singh

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: How Can I use Google Calendar in my Site Link to this post

    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

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