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

Exclude page.media.images|first

Started by Muut Archive 9 years ago · 4 replies · 1313 views
9 years ago

Is it possible to read all images execpt the first one? We need this at the blog page. First Image should be the header image and all other images should be a gallery.

Maybe there is a ready to use solution, but couldn't find it...

9 years ago

I think you could just set a variable to be equal to page.media.images|first, and then you pull in the images for your gallery have a statement to the effect of, "for images in.... If not equal to <aforementioned variable>... Print image" I'm on mobile so can't mock up the actual code

9 years ago

I tried something like this - but not working...

{% for image in page.media.images %}
{% if not page.media.images|first %}
<a href="{{ page.url }}" data-lightbox="gallery-item">{{ image.html }}</a>
{% endif %}
{% endfor %}

9 years ago

:-) yeah

Found a solution....

<div class="masonry-thumbs col-{{ header.gallery.cols }}" data-big="{{ header.gallery.big_picture }}" data-lightbox="gallery">

TWIG
        {% for image in page.media.images %}
            {% if image == page.media.images|first %} 
                <!-- do nothing, ignore that image -->
            {% else %}
                <a href="{{ image.url }}" data-lightbox="gallery-item">{{ image.html }}</a>                 
            {% endif %}
        {% endfor %}

</div>

Come and see it in action: https://www.giesinger-ender.at/test-mit-fotos

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1336 9 years ago
Archive · by Muut Archive, 9 years ago
2 926 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago