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

Printing out the count of media files

Started by Muut Archive 10 years ago · 2 replies · 537 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 1357 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago