1

I have a page that is supposed to render the content and then force a download of a file.

I have {% header "Location: " ~ entry.files[0].url %} in my template which brings up the browser's save dialogue window, but then the page doesn't render.

Is there a way I can delay the setting of the {% header %} tag until after the page has rendered? Or is there a better way of doing what I'm trying to achieve?

2

The {% header %} tag probably isn't what you want then - they must be rendered first, as they affect what the webserver is returning to the browser in the page headers. Because you're setting the location header to the file url, it is telling the browser to redirect to that instead of rendering the rest of the page (which would still technically be rendered by the server, just never seen by the browser).

It sounds like the better option would be to trigger the redirect to the file location via javascript after the page loads, similar to this approach.

  • Thanks, that did it. 👍 – Tyssen Apr 16 '20 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.