Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Provide page for download and change content-type

Started by Muut Archive 10 years ago · 3 replies · 520 views
10 years ago

Hi, I'm trying to provide an iCalendar file for download which content is generated with Twig.
So I crated a new template "icalendar.html.twig" which actually contains just one line saying

TWIG
{{ page.content }}

and created a new page "/calendar/icalendar.md" of that template with content

TXT

title: calendar
process:
twig: true
markdown: false
cache_enable: false
visible: false
template: icalendar
content:
items:
'@taxonomy':
type: event
order:
by: date
dir: asc
limit: '20'
pagination: false

TWIG

{% set events = page.collection({'items':{'@taxonomy.type':'event'}}).order('date', 'asc') %}
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//SabreDAV//SabreDAV//EN
CALSCALE:GREGORIAN
... and so on.

Now, what I get returned looks like an iCalendar file.
However, it cannot be parsed by some calendar software like Thunderbird/Lightning and I think that's due to two reasons:

1 If I enter /calendar/calendar.ics into the browser address bar, the file opens in the tab rather than providing me to download it.

2 The content-type is text/html instead of text/calendar

To fix the 2nd problem I copied the /system/config media.yaml to /user/config/media.yaml and added

YAML
   ics:
    type: file
    mime: text/calendar

But this seems to be totaly ignored as the content-type is still text/tml.

So my questions are:

  • Did I made a completey worng turn somewhere here?
  • Or how do I change the content-type and how do I achieve to provide the file as a download instead opening it in the browser tab?

Best regards,
Phil

10 years ago

You should add the type .ics to the pages: types: in the system config. Also you should rename your twig to icalendar.ics.twig. I think that should do it!

10 years ago

OK, I renamed the twig template to icalendar.ics.twig and added the ics file type to pages: types: in both, the /system/config/system.yaml and /user/config/system.yaml
But the content-type is still text/html and it still opens in the browser tab.

At least I figured out the iCalendar parsing error was not related to this circumstances, so it might not be perfect, but it works now.

-Phil

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1282 9 years ago
Archive · by Muut Archive, 9 years ago
2 889 9 years ago
Archive · by Muut Archive, 9 years ago
2 4019 9 years ago
Archive · by Muut Archive, 9 years ago
1 2894 9 years ago
Archive · by Muut Archive, 9 years ago
3 1078 9 years ago