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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Loop over Images in content split

Started by Niko Kaindl 8 years ago · 1 replies · 746 views
8 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

8 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 Pedro M, 2 months ago
4 193 2 months ago
Themes & Styling · by Ian, 2 months ago
3 91 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 451 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 45 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 125 3 months ago