Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

How to get correctly PDF file from directory for downloading

Started by Muut Archive 10 years ago · 3 replies · 584 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 Muut Archive, 10 years ago
1 676 1 week ago
Archive · by Deleted User, 9 years ago
0 3043 9 years ago
Archive · by Muut Archive, 9 years ago
2 1983 9 years ago
Archive · by Muut Archive, 9 years ago
2 5337 9 years ago
Archive · by Muut Archive, 9 years ago
1 4134 9 years ago