joe_g Posted February 16, 2022 Share Posted February 16, 2022 (edited) Hi there, If I try to add a custom header it gets removed by PW header('Content-type: text/calendar; charset=utf-8'); I can see that $http->setHeader was introduced in v.193, but not yet in the stable branch. I assume it should work with the new way to set a header. What can i do to achieve this in the stable branch? thanks! Edited February 22, 2022 by kongondo Moderator Note: Merged here from original thread. Link to comment Share on other sites More sharing options...
joe_g Posted February 22, 2022 Author Share Posted February 22, 2022 Hi all, I'm trying to generate .ics / iCalendar files from PW, but PW strips custom headers. Is there a way I can do this? Many thanks. (This is a repost, sorry - trying a better title for better traction) Link to comment Share on other sites More sharing options...
3fingers Posted February 22, 2022 Share Posted February 22, 2022 Reading from the docs I've found this: https://processwire.com/api/ref/wire-file-tools/send/ where you can specify, among other options, the content-type for the file you'd like to serve. Does it fits your needs? Link to comment Share on other sites More sharing options...
kongondo Posted February 22, 2022 Share Posted February 22, 2022 39 minutes ago, joe_g said: This is a repost, sorry - trying a better title for better traction Double posting is not allowed. You could have edited the title of your first thread ?. I'll delete the other thread. 1 Link to comment Share on other sites More sharing options...
Robin S Posted February 22, 2022 Share Posted February 22, 2022 On 2/16/2022 at 11:59 PM, joe_g said: header('Content-type: text/calendar; charset=utf-8'); It works for me. Template file: <?php namespace ProcessWire; header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="my-file.ics"'); ?> BEGIN:VCALENDAR VERSION:2.0 PRODID:-//ZContent.net//Zap Calendar 1.0//EN CALSCALE:GREGORIAN METHOD:PUBLISH BEGIN:VEVENT SUMMARY:Abraham Lincoln UID:c7614cff-3549-4a00-9152-d25cc1fe077d SEQUENCE:0 STATUS:CONFIRMED TRANSP:TRANSPARENT RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12 DTSTART:20080212 DTEND:20080213 DTSTAMP:20150421T141403 CATEGORIES:U.S. Presidents,Civil War People LOCATION:Hodgenville\, Kentucky GEO:37.5739497;-85.7399606 DESCRIPTION:Born February 12\, 1809\nSixteenth President (1861-1865)\n\n\n \nhttp://AmericanHistoryCalendar.com URL:http://americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincol n END:VEVENT END:VCALENDAR Result: Make sure you're not prepending or appending any other file to the template that could be messing things up (including automatic prepend/append in $config). 2 Link to comment Share on other sites More sharing options...
joe_g Posted April 7, 2022 Author Share Posted April 7, 2022 Thank you! Indeed it worked, after adding the namespace. It's embarrassing but I still don't full understand namespaces. Or rather, I kinda do but I'm not sure when I need to declare "namespace ProcessWire;" in a PW template... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now