Roughly, it should be possible to use the iCal file contents as a template. I don’t think Kirby cares what its generating.
You should be able to use a loop in a route to fill in the contents, I have done this to save a json file to disc that Kirby generated, and the process should be pretty similar.
The only gotcha I can think of is that I don’t know if the ical file format is sensitive to white space and line breaks that you might end up with. I can see in an example there are slashes for escaping things and newlines, im not quite sure how to handle that, but im sure someone can help you out there.
See this post.
Roughly something like this in a route should do it:
c::set('routes', array(
array(
'pattern' => 'events.ics',
'action' => function() {
header('Content-Type: text/calendar; charset=utf-8');
$events = site()->index()->visible()->eventstructurefield()->toStructure();
foreach ($events as $event) {
// your structure field data
}
}
)
));
Then when you visit yourdomain.com/events.ics
you will get the ics file I think if you get people to point their calendars at that URL rather doing file downloads, it will be “live” as in when new events get added, they will feed through to the calendars. If you offer a download, the events are fixed at that point in time.