Skip to content
Grav 2.0 is officially stable. Read the announcement →
Themes & Styling

Loop over Images in content split

Started by Niko Kaindl 9 years ago · 1 replies · 859 views
9 years ago

Hi I have the following problem:

I would like to include the page.media.images in my Content-Loop in an ascending manner. I Understand how to get the first one, but not the rest of the pictures. I tried it also with the slice filter and loop.index, but it did not work.

TWIG
{% for column in page.content|split('<hr />') %}
<div class="content">{{ column }}</div>
<div class="image">{{ page.media.images|slice('~loop.index~',1) }}</div>
{% endfor %}

Any Suggestions?

Thanks a lot!

Niko

9 years ago

Well I did find a work around, but it's not nice:

TWIG
{% for column in page.content|split('<hr />')  %}
{% set col = loop.index %}

<div class="row">

{% for image in page.media.images %}
{% if loop.index == col %}
{{ image }}
{% endif %}
{% endfor %}

{{ column }} </div>

{% endfor %}

If someone know a cleaner approach, that does not loop through all the pictures for every iteration, i would still be even more happy...

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Sebadamus, 2 days ago
4 78 57 minutes ago
Themes & Styling · by martynfoster735, 5 days ago
1 161 3 days ago
Themes & Styling · by Justin Young, 3 weeks ago
1 223 3 weeks ago
Themes & Styling · by Slebeig, 1 month ago
4 350 1 month ago
Themes & Styling · by Pedro M, 3 months ago
4 709 3 months ago