<p>You could track the total used columns in a var and check if its less than 12.</p>

<pre><code>{% set col_count = 0 %}
{% for item in items %}
    {% switch item.type %}
        {% case "value1" %}
            {% set col_size = 4 %}
        {% case "value2" %}
            {% set col_size = 6 %}
    {% endswitch %}

    {% if not loop.first and (col_count + col_size) &gt; 12 %}
        &lt;/div&gt;
        {% set col_count = 0 %}
    {% endif %}

    {% if col_count == 0 %}
        &lt;div class="row"&gt;
    {% endif %}

    {% set col_count = col_count + col_size %}

    &lt;div class="column small-{{ col_size }}"&gt;
        {{ item.title }}
    &lt;/div&gt;

    {% if loop.last %}
        &lt;/div&gt;
    {% endif %}

{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-08-10T08:04:14.390Z
2018-08-10T08:04:14.390Z
RvdB
<p>I need to figure out how to close out the columns if it equals 12 and then open a new row. I have a Matrix field set up with rows, but it needs to break with a new row if the columns equal 12.</p>

<p>Any suggestions?</p>

<craft3><bootstrap-craft>
Close bootstrap row and start a new row Matrix
# Close bootstrap row and start a new row Matrix

(Asked by: username_0 on 2018-08-09)

I need to figure out how to close out the columns if it equals 12 and then open a new row. I have a Matrix field set up with rows, but it needs to break with a new row if the columns equal 12.

Any suggestions?

**Tags:** craft3, bootstrap-craft

---

## 1 answers

### Answer by username_1 on 2018-08-10. Score: 1

You could track the total used columns in a var and check if its less than 12.
{% set col_count = 0 %}
{% for item in items %}
    {% switch item.type %}
        {% case "value1" %}
            {% set col_size = 4 %}
        {% case "value2" %}
            {% set col_size = 6 %}
    {% endswitch %}

    {% if not loop.first and (col_count + col_size) > 12 %}
        
        {% set col_count = 0 %}
    {% endif %}

    {% if col_count == 0 %}
        
    {% endif %}

    {% set col_count = col_count + col_size %}

    
        {{ item.title }}
    

    {% if loop.last %}
        
    {% endif %}

{% endfor %}


---

