Is it possible to serve a file in a Twig template? I need to get a file (asset) from a global setting, and serve it at a particular URL.
This code is close, but it seems that source()
is the wrong method to get the file contents with.
{% header "Content-type: application/pdf" %}
{% header "Content-Disposition: inline" %}
{% set filePath = [craft.config.environmentVariables.assetPath, filesImages.deliveryCalendar[0].filename]|join('') %}
{{ source( filePath ) }}
The variable filePath
contains the correct system path to the file (/var/www/site.com/html/assets/file.pdf), but source()
is clearly for templates and not files.
How can the contents of a file be streamed out to the browser?
{{ dlfile(cal.pdfFile[0].id) }}
to dump the contents of the PDF. gist.github.com/emcniece/bcf3d902e5469613fb1c