Post
Today, you get a little how to for creating iCal compatible calendars from Textpattern. This is most useful if you use Textpattern to store events, and really useful if you use it to store gigs in, like The Rogers Sisters Website does. The following requires a bit of textpattern knowledge (of various txp: tags and the like), but I’m going to try and make it as clear as possible.
Just for a bit of background, the gigs on the Rogers Sisters site are stored as articles in a section called “gigs”, with the venue and place as the article title, any further description (like who’s supporting) in the body, and the gig date as the posted date.
Then to display the gigs you simply use an article_custom tag, with the date set to future like this:
<txp:article_custom form="gig" time="future" section="gigs" sortdir="asc" limit="25" />
Now, on to the calendar! To start with, the file format that iCal uses is called .ics, and is used by several other calendar programs so hopefully this should work with any .ics compatible program. The key piece of information that makes this all fairly straightforward is that .ics is a text based format, and a fairly simple one at that, so we can output a page from textpattern that complies to the .ics format, and can hence be used in iCal.
First, set up a new section in Textpattern (in presentation -> sections) – I called mine “gigcalendar”, and make it use a new blank page by creating a new page in the pages tab, and then setting the section to use it.
Next, copy the code below into the blank page (making sure you don’t have anything else, including any html, on the page):
BEGIN:VCALENDAR
VERSION:2.0
X-WR-CALNAME:Gigs Calendar
PRODID:-//Apple Computer, Inc//iCal 1.5//EN
X-WR-TIMEZONE:Europe/London
<txp:article_custom form="gigsicsitem" time="any" section="gigs" sortdir="asc" limit="10000"/>
END:VCALENDAR
Now, what this does it output the required .ics header and footer and then get the gigs we want to show up in the calendar (we’re after both past and future gigs, hence the
time=”any”), using the “gigsicsitem” article form, which is what outputs each event.
Next, go over to the forms tab and create a new article form (what I’ve called ‘gigsicsitem’), and past in the code below:
BEGIN:VEVENT
DTSTART:<txp:posted format="%Y%m%d" />T193000
DTEND:<txp:posted format="%Y%m%d" />T230000
SUMMARY:<txp:title />
END:VEVENT
This simply outputs each event in the correct formatting for .ics use. The DTSTART and DTEND are probably the only things that need explaining. These are the start and end times of the event, the first part of which is the date in yyyymmdd format, which we create using the “format” argument of the txp:posted tag. The second part is the exact time of the event (hence it starting with “T”). As we’re dealing with gigs, I’ve made some assumptions as most gigs start at 19:30ish and end at 23:00, so I’ve hard coded the times in. You could, however, quite easily use different formatting on the txp:posted tag to get the posted time as well. To make the end date you could always use a custom field as well, as textpattern only has one date field.
After you’ve done all that, your “gigscalendar” section should be outputting a valid .ics file, so simply take the url ( e.g. http://www.yoursite.com/gigscalendar ) and in iCal under the “Calendar” menu, click the “Subscribe…” menu item and enter the address.
That’s it! Hope this might be useful to someone out there…















@DavidEmery




Comments
Was very useful, thanks a lot!
Thanks for share this information, i really didn’t know about that, will get advantage from this,Thanks for share this.
Great tutorial. It will be very important for me to organize my tasks. Thank you!
Very didactic explanation. Even knowing little textpattern, I managed to implement the codes and obtain success. Thank you for sharing your knowledge.
Rather than going through this process manually or by creating an applescript to do it would be to enable personal web sharing (and php), install phpicalendar (open source) and configure it to look at your ~/Library/Calendars/ directory for the calendars, and use an application such as webdesktop (freeware) to display your phpicalendar enabled iCal information.
An update to my earlier note here – the synchronization works indeed – it just took a while to get there even when i did a manual refresh in ICal. The tasks ended up in my calender as 2hrs task – even though i specified 1hrs or 30mins – why is that ? Thanks.
Great bit of code, and I think this calender will sync with Outlook?
Nice, keep it up.. Thanks for the info..
Great tip! I set this up in a few minutes…
Two additional tips from me: – You can skip DTEND if you don’t want to define an ending time (I’m using this for gigs as well, and for me that’s even more practical than defaulting to 11pm) – Use the handy aks_header plugin (http://textpattern.org/plugins/1117/aks_header) and call it on the first line with the following attributes to ensure the file is sent with the correct headers
<txp:aks_header name=“Content-Type” value=“text/calendar” strip=“0” gzip=“0” nodebug=“0” />
Maybe this is of some use to someone!
Cheers!
Really helpful for me.
I have learned a lot from this.
iCal compatible calendars from Textpattern, it’s great!
Pretty nice website. Thanks for the tutorial.
Indeed a nice tutorial. Could be very useful to greate iCall calendars´ from textpattern.