How to handle twig view and bootstrap 3 rows/columns?
UPDATED:
As @Maerlyn suggested:
{% for row in articles|batch(2) %} <div class="row"> {% for article in row %} <div class="col-md-6"> // your content </div> {% endfor %} </div>{% endfor %}
OLD way:
Use loop.index
(doc: The loop variable), modulo (doc: Math operators) and if
(doc: if
statement )
{% for article in articles %} {% if loop.index % 2 == 1 %} <div class="row"> {% endif %} <div class="col-md-6"> // your content </div> {% if (loop.index % 2 == 0 or loop.last) %} </div> {% endif %}{% endfor %}
{% for row in articles|batch(2) %} <div class="row"> {% for article in row %} <div class="col-md-6"> // your content {% if loop.index is divisibleby(3) %} </div> {% endif %} {% endfor %} </div>{% endfor %}
I suggest :
<div class="row">{% for article in articles %}{% if (loop.index0 % 2 == 0) and not loop.first %}</div><div class="row">{% endif %} <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"> // your content </div>{% endfor %}</div>