Hello I am trying to create a foto gallery using twig and bootstrap that has an algorithm for width. Example: I hope its clear every section is devided by a thicker black line.
So I tried allot of things out but now it seems im close to the solution but its still not working properly this is my code atm:
<section>
<div class="row row-no-gutter">
{% setcontent miniaanbod = "aanbod" %}
{% for items in miniaanbod|reverse %}
{% set cols = 3 %}
{% set totaal = miniaanbod|length %}
{# this is the beginning. #}
{% if totaal - cols <=0 %} {# if the total is less than 0 it means it is 1 or 2. so my colwidht would be or 6 or 12 #}
{% set colwidth = 12/totaal %} {# expected that totaal is 1 or 2 here #}
{% else %}
{% set totaal = totaal - cols %} {# expected that if the totaal is 4 it takes of 3 and goes back to the begining with 1. so the first IF statement can catch it. #}
{% set colwidth = 12/3 %} {# expected that totaal is 3 here so most likely I can just do 12/3 so I did that #}
{% endif %}
{#{{ dump(colwidth) }}#}
<div class="col-sm-6 col-md-{{ colwidth }}">
<div class="product">
<img src="{{ image(items.gallerij[0].filename, 1620, 880) }}" alt="">
<div class="product__cnt">
<h5 class="uppercase">{{ items.type }}</h5>
<ul class="pricing-table">
<li>Prijs : <span class="price">{{ items.prijs }}</span></li>
</ul>
<span class="link"><a href="/aanbod/{{ items.slug }}">Continue</a></span>
</div>
</div>
</div>
{% endfor %}
</div>
</section>
what this does it changes all the pictures to col-md-4
but what it should do is after every 3 items it has to return to the start of the if
statement. but I cant seem to get it to the beginning again. I also tried to put another for
loop inside the other for
loop to get it to return to the beginning after every item but then it always creates col-md-12
becouse it only has one item at a time.