Make block action bypass page rendering for file download?

Permalink
Hi all

I've created a block which generates an .ics file on-the-fly (for calendar software) using an action in the block's controller called download_ical. This works great for generating the file and downloading it automatically, using PHP's header() function.

My problem arises when I plug the URL into software like Outlook. The website's HTML is still being put through to the browser/calendar client and therefore the 'calendar' is obviously invalid, and the import fails.

Is there a way for a block's action to bypass the rendering of the page, so the only data that is sent to the browser (or calendar client) is the data outputted by the block's method?

I have this header code, which works to download the new file, but doesn't prevent the website's HTML from being sent to the requesting client:

header('Content-type: text/calendar; charset=utf-8'); 
            header('Content-length: ' . strlen($ical)); 
            header('Content-Disposition: inline; filename="calendar.ics"'); 
            echo $ical;
            exit();


$ical contains the (valid) ical data.

Any thoughts? Any help much appreciated :)

melat0nin
 
melat0nin replied on at Permalink Reply
melat0nin
I've worked it out by using the RSS function of the Page List block as a template. The idea is to create a 'tool' in the block's file structure, and pass the relevant information through to it which then outputs the necessary data. This bypasses the rendering of the page, which is exactly what I was after :)