Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Printing out the count of media files

Started by Muut Archive 10 years ago · 2 replies · 630 views
10 years ago

Hey there everybody. In one of my template partials, i want to print out (html) a list of files. That already works well for all the zip files i add to the post / pages folder. But i would love to have the count of the attached files showing in the header - wich i tried with .length and .count. But neither one gives me any output. What am i doing wrong?

TWIG

{% set attachementList = page.media.files() %}
{% set attachementCount = attachementList.length() %}
{% if attachementList %}
<h3>{{ attachementCount }} Anhänge (Downloads)</h3>
<ul>
{% for mediaItem in page.media.files %}
<li><a href="{{mediaItem.url}}">{{mediaItem.text}}</a></li>
{% endfor %}
</ul>
{% endif %}
---
10 years ago

Works perfect! Thank you.
(And now i get how those "filters" work.)

Thanks!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 2288 9 years ago
Archive · by Muut Archive, 9 years ago
2 1500 9 years ago
Archive · by Muut Archive, 9 years ago
2 4753 9 years ago
Archive · by Muut Archive, 9 years ago
1 3570 9 years ago
Archive · by Muut Archive, 9 years ago
3 1626 9 years ago