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

How to get correctly PDF file from directory for downloading

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

Good day! Can you please suggest what is the best way to scan the directories for PDF files and create the download links from them.

---twig
{% for book in pages.find('/media').children %}
{% for a in book.media.files() %}
<a href="{{ a.items.filepath }}">{{ a.items.basename }}</a>
{% endfor %}
{% endfor %}

10 years ago

Almost forgot, how we can print out only the PDF files?

10 years ago

Your code looks like it should work fine. is it not? You should be able to inspect the extension ie:

TWIG

{% if a.extension == 'pdf' %}
...
{% endif %}
---
10 years ago

Thank you. Just thought there is another way... just for learning... :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1366 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago