How to make Grav send a file as a download

I want to make a button that, when clicked, will send a download file of relevant data. I know you can do this in PHP - is there a way to it in Grav, or maybe an existing plugin, or will I have to write my own plugin?

Can you tell us a bit more? This might be possible without a plugin just by configuring media.yaml in your config:

  • you need to establish the link to the data document
  • if your data document is in a format not already listed in media.yaml, you may need to add it in system/config/media.yaml as described in the docs

Generally with a plain HTML link, it’s the user’s browser that will decide how to handle it (view or download).

It’s hard to say more without trying to guess what you are doing.

Thanks Hughbris.

My club has an events page where event notices from many related clubs gets posted. The events editor, who’s not techy at all, logs in and creates a new event page whenever she’s told about an event. Every quarter, she publishes the current list in a paper-based newsletter, so she wants to be able to get the list in plain text format and drop it straight into the Word document for the newsletter.

So it’s not a simple case of making a page with a button that links to a preset document. It needs to be a page whose template starts by compiling a list of the events, concatenated into a long string, and then that has to be delivered to her. I can do it easily enough by making a Form page that will email it to her, so that she can copy and paste it into the newsletter; but the system that we’ve been using allowed me to make a button that caused the list to be immediately downloaded. As she’s a very busy woman she loved having a one-click system, and if I can reproduce it I’d like to.

Regrettably my skills and courage falter when I read the instructions for building a plugin - I’m not that much of a techie either. So if it’s not possible without a plugin, she’ll have to put up with the email version.

Hope that’s clear! Thanks again for your interest.