As most Drupalers have realized, iCal support for Drupal is in its infancy. The first successful implementation of it was only realized at the beginning of 2007 in the calendar module. It still has a lot of limitations - there are issues with time zones, and a complete lack of customization that CCK offers.

For the Brown University Featured Events website, I wanted to have an iCal field with a custom description, title and location. I wanted to be able to say what is the start and end date, and what is all day and what isn't. All of that while using a CCK content type with various fields we chose in order to optimize data entry (we did not use event or event repeat modules).

Sadly, I just cannot do all of that with the calendar module.

Without creating a custom module, I was able to generate a custom iCal feed. The general concept is as follows:

  1. Create a view to generate all desired events
  2. Theme the event nodes to iCal specifications
  3. Clean up node data for iCal specifications
  4. Output the page as an iCal file

First, I created an output of the events, a view would work. I then themed events to display in the iCal standard, allowing me to put my CCK fields anywhere I wanted (example: node-event-ical.tpl.php). You need to take special care within the template to ensure proper line breaks - hence the generous usage of "\n" in my example. I only needed to support one off events, which my example represents. You would need to add support for repeating events if you need it.

All the text and dates need to be formatted correctly for iCal which I created helper functions for. One converts the date from ISO to iCal standard, and the other removes all line breaks and escapes commas in the text. See ical-api.php for the helper functions. They may be added to your theme's template.php file, or a custom module.

Now that the event nodes are themed in proper iCal format, the page displaying the events also needs to be in an iCal format. I typically bypass using the default page theme by placing the following at the top of page.tpl.php.

<?php
 
// assuming the system path is foo/bar
 
if(arg(0) == 'foo' && arg(1) == 'bar') {
    include (
'page-ical.tpl.php');
    return;
  }
?>

The file page-ical.tpl.php will be formatted to iCal specifications, and the header set to return as an iCal file instead of a webpage. (example page-ical.tpl.php)

This same process can be used for custom XML, too!

AttachmentSize
ical-api.php - Helper functions for iCal1.23 KB
node-event-ical.tpl.php - Theming an event node in iCal standards1.19 KB
page-ical.tpl.php - Theme the page to putput as an iCal file393 bytes

"iCal support" can mean a lot of things (i.e. read only iCal feeds vs. read-write). However, iCal read-write has been provided for a long time in the Event module:

I published this screencast of how to use it back in May of 2006 and it was working for at least a while before that.

Your approach and information is certainly helpful as well for those that want to build a more customized iCal feed.

I meant to say "iCal read-only has been provided..."

This is an interesting and lightweight approach. Ideally this would be a views plugin though surely? That would take care of if statements on the page.tpl for a start, and still allow you to theme the result anyway. Does this sound correct? If so, I'll try & write an ical views plugin for Drupal 6.

This is an interesting and lightweight approach. Ideally this would be a views plugin though surely? That would take care of if statements on the page.tpl for a start, and still allow you to theme the result anyway. Does this sound correct? If so, I'll try & write an ical views plugin for Drupal 6.

There is a means to output events as an ical feed with views, however, it's not customized. I can't say what CCK fields should go where.

I wanted an arbitrary text field to be set as the event's location within the iCal standard. I also had some manipulation of the date and descriptions as well.

Since CCK is so valuable, we should add more flexible support for iCal and XML output.

More customization is coming in the D6 version of Calendar for Views 2. It is just too hard to do in Views 1, but in Views 2 there will be ways to identify what fields should be linked to what ical values.

That was me in the comment above, not 'Anonymous' :)

Presumably you could still alter/customize the views plugin tpl files just like any other tpl files. The plugin way would just save having to update any if/then comments in your page template.

More customization is coming in the D6 version of Calendar for Views 2. It is just too hard to do in Views 1, but in Views 2 there will be ways to identify what fields should be linked to what ical values.

Thats really great! I'm looking forward to it.