I currently have checkboxes in a matrix block that allow a user to select where an image will be placed in the layout (as a featured slider image and/or in an image gallery). I've gotten the slider image to function but if, for some reason, there are no featured images I have a couple of unnecessary <div>
tags. Because I am selecting only featured images from the matrix block I can not use loop.first
and loop.last
to move those divs in my for loop.
I had seen an article that seems close to finding the answer to my problem here : Only execute twig block if a Matrix radio has a certain value but I haven't been able to make it work.
Any help would be greatly appreciated.
{# Add Feature Images - Slideshow #}
{% set photos = entry.photoGallery.type( 'photos' ) %}
{% if photos|length %}
<div class="row" >
<div class="slidr">
{% for block in photos if block.imageLocation.contains('featured')%}
{# Get the photo #}
{% for photo in block.photo %}
<div class="figure">
<a href="{{ photo.getUrl }}">
<img src="{{ photo.getUrl('projectHero') }}" alt="">
</a>
{# Get the caption #}
{% if block.caption|length %}
<div class="caption">{{ block.caption }}</div>
{% endif %}
</div>
{% endfor %}
{% endfor %}
</div>
</div>
{% endif %}