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

Looping over images in a media folder

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

Hi there. I am thinking of using Grav to build an artist's portfolio website. I am still in the early stages, just playing around, but I'm having trouble using Grav's media functionality to loop over images in a media folder. This is what I am trying, and nothing shows up:

TWIG
{% for image in page.find('/paintings').media  %}
   {{ image.resize(270, 190).html() }}
{% endfor %}

But it works just fine if I do it on a single image by name, like this:

TWIG
{{ page.find('/paintings').media['01Full.jpg'].resize(270,190).html() }}

So far, the only way I have found of getting the looping code to work is to manually upload each image onto a page in the adminterface.

What is going on here? Is this a bug? Thanks for any help.

-jed

10 years ago

Ok, I guess I figured it out. If I do:

{% for image in page.find('/paintings').media.images %}

it works. Though given that individual images are accesible directly on the media object, and that this format is all over the documentation, and that there are no examples of the looping, I don't think my confusion was unreasonable.

10 years ago

Also, never mind that bit about the adminterface. I was wrong about that.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1369 9 years ago
Archive · by Muut Archive, 9 years ago
2 942 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