I’ve a full width gallery on the top of my page that simply loops over all images as follows:
{% for image in page.media.images %}
<div data-src="{{ image.url }}" data-thumb=""></div>
{% endfor %}
A few lines lower I’ve another image that is take from the page directory.
<div class="bit-25 profile-img right">
{% if profile_image %}
{% if profile_image_file %}
{% set profile_image_media = page.media.images[profile_image_file] %}
{% else %}
<img src="{{ url('theme://images/profile.jpg') }}" class="profile-image"/>
{% endif %}
{{ profile_image_media.html('Title', 'Alt', 'Class') }}
{% endif %}
</div>
---
As you can see I set the 'profile image' based on toggle. If yes, then check the field 'profile_image_file', where the user provided the name of the image it wants as profile image.
This all works perfectly fine.. the only problem is that the profile image, being located in the page directory is also loaded in my full width gallery on top of my page.
Is there a way to exclude this profile image from the first for loop, based on the name provided in 'profile_image_file'?
maybe something like?
{% for image in page.media.images %}
{% if page.media = profile_image_file %}
{% endif %}
{% endfor %}
Im sure its possible with grav, but so far i've had no luck trying to exclude it from my for loop.
I just tried the below, but also not working. Eventhough im 99% sure that for the image im targeting the image.urland page.media['profile_image_file'].url are identical.
{% if image.url == page.media['profile_image_file'].url %}
<!--ignore this image -->
{% endif %}
---
Once again, I can’t test it right now but here is another thing you might try:
{% for image in page.media.images if image is not == page.header.profile_image_file %}
<div data-src="{{ image.url }}" data-thumb=""></div>
{% endfor %}
Also, you can check if the two urls are identical by enabling the debugger in the configuration page and with the command dump()