ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Problem with icalendar / ics template

November 18, 2010 2:29pm

Subscribe [4]
  • #1 / Nov 18, 2010 2:29pm

    Social Spark

    11 posts

    Hi there

    I’ve got a channel of events, and am trying to add a button next to each entry so users can download it to their calendar.

    I’ve created a template to generate the ics file. It works fine in Safari but other browsers don’t seem to recognise it as an ics file and just open it as text in the browser. I suspect the problem may be to do with the mime type, but the php at the top doesn’t seem to help (and Safari opens it as ics correctly with our without the php).

    I have my template type set to Web. Other types, including xml, just generate errors.

    Here’s the template code, though I don’t think that in itself is the problem. In fact I’ve tried pasting in static ics code, which I know works on another site, and still get same issue - ok in Safari but not in anything else.

    <?php 
    header ("Content-Type: text/Calendar"); 
    header ("Content-Disposition: inline; filename=iCalendar.ics"); 
    ?>
    BEGIN:VCALENDAR
    X-WR-TIMEZONE:Europe/London
    PRODID:-//False Economy//NONSGML v1.0//EN
    CALSCALE:GREGORIAN
    X-WR-CALNAME:False Economy
    VERSION:2.0
    {exp:channel:entries channel="events" show_future_entries="yes" disable="member_data|pagination|categories" limit="1"}BEGIN:VEVENT
    UID:{entry_id}-falseeconomy
    URL;VALUE=URI:http://falseeconomy.org.uk/campaigns/event/{url_title}
    DTSTAMP:{entry_date format="%Y%m%dT%H%i%sZ"}
    DTSTART:{entry_date format="%Y%m%dT%H%i%sZ"}
    DTEND:{entry_date format="%Y%m%dT%H%i%sZ"}
    LOCATION:{evestreet1}, {evetown} {evepost1} {evepost2}
    SUMMARY:{title}
    DESCRIPTION:{exp:tagstripper:stripAllTags}{evetext}{/exp:tagstripper:stripAllTags}
    END:VEVENT{/exp:channel:entries}
    END:VCALENDAR

    Any advice would be very welcome.

  • #2 / Nov 19, 2010 3:32am

    John Henry Donovan

    12339 posts

    Clifford,

    Add an exit; right after your last header function

    <?php 
    header ("Content-Type: text/Calendar"); 
    header ("Content-Disposition: inline; filename=iCalendar.ics"); 
    exit; 
    ?>
  • #3 / Nov 19, 2010 7:31am

    Social Spark

    11 posts

    Thanks for that John. That got me half way - the file was recognised at ics by different browsers but my calendar said it was unreadable. But I tracked down a solution - wrapping the whole thing in php. Here’s the working template in case it’s useful for anyone else:

    <?php 
    $ical = "BEGIN:VCALENDAR
    X-WR-TIMEZONE:Europe/London
    PRODID:-//False Economy//NONSGML v1.0//EN
    CALSCALE:GREGORIAN
    X-WR-CALNAME:False Economy
    VERSION:2.0
    {exp:channel:entries channel="events" show_future_entries="yes" disable="member_data|pagination|categories" limit="1"}BEGIN:VEVENT
    UID:{entry_id}-falseeconomy
    URL;VALUE=URI:http://falseeconomy.org.uk/campaigns/event/{url_title}
    DTSTAMP:{entry_date format="%Y%m%dT%H%i%sZ"}
    DTSTART:{entry_date format="%Y%m%dT%H%i%sZ"}
    DTEND:{entry_date format="%Y%m%dT%H%i%sZ"}
    LOCATION:{evestreet1}, {evetown} {evepost1} {evepost2}
    SUMMARY:{title}
    END:VEVENT{/exp:channel:entries}
    END:VCALENDAR";
    
    //set correct content-type-header
    header('Content-type: text/calendar; charset=utf-8');
    header('Content-Disposition: inline; filename=calendar.ics');
    echo $ical;
    exit;
    ?>
  • #4 / Nov 19, 2010 11:24am

    Ingmar

    29245 posts

    Thanks for sharing your solution with us. Please post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases