Jump to content

how to header('Content-type: text/calendar'); from a template


joe_g
 Share

Recommended Posts

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 by kongondo
Moderator Note: Merged here from original thread.
Link to comment
Share on other sites

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

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.

  • Thanks 1
Link to comment
Share on other sites

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:

2022-02-23_102243.png.501bcdab66801b872601ab8c28aac19b.png

 

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).

2022-02-23_102536.png.e8bc3dd47291a992a404b4c18eadc21a.png

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...