Hello,
I’m creating a highly specific template for a site.
It’s a modular page. In one of the sub folders (lets call it _slider) are a variable amount of images.
How can I loop over all images and get their url (in the slider.html.twig) without knowing their names and number beforehand?
Cheers
@nembgen Here is a small sample that might send you in the right direction.
Say you have a modular page with template ‘templates/modular.html.twig’, which loops through all child modules for the modular page:
...
{% for module in page.collection() %}
<div id="{{ _self.pageLinkName(module.menu) }}"></div>
{{ module.content }}
{% endfor %}
...
And you have a folder like:
pages/
01.home/
_slider/
image1.jpg
image2.jpg
...
slider.md
_other_modules
...
Then the following template ‘templates/modular/slider.html.twig’, will loop through all images in folder ‘_slider’:
{% for image in page.media.images %}
<img src="{{ image.url }}">
{% endfor %}
1 Like
Awesome! Thank you, it’s working.
Cheers