Create a new row every 3 items in a matrix I need to output a row every three items in a matrix. Here is what I have so far. The problem is that this outputs a row every three items but it duplicates each matrix item three times and puts them in a row rather than taking the items as they come. Any help here would be very much appreciated Thanks.

{% set aboutInfo = entry.imageLinkBoxes %}
{% set infoGrouped = aboutInfo|batch(3) %}

{% for group in infoGrouped %}
    {% for block in entry.imageLinkBoxes %}

        {% if block.type == "imageLinkBox" %}

            {% set row = 'row--' ~ loop.index %}

            &lt;div class="row {{ row }}"&gt;
                {% for entry in group %}

                    &lt;div class="span4"&gt;
                        &lt;div class="icon-box-2"&gt;    
                            &lt;i class="ifc-tv_show"&gt;&lt;/i&gt;
                            &lt;div class="icon-box-content"&gt;
                                &lt;h3 class="text-uppercase text-center"&gt;
                                    &lt;a href="#"&gt;{{ block.entry.first().title }}&lt;/a&gt;
                                &lt;/h3&gt;
                                &lt;p&gt;{{ block.text }}&lt;/p&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;               
                    &lt;/div&gt;

                {% endfor %}
            &lt;/div&gt;

        {% endif %}

    {% endfor %}
{% endfor %}
To my understanding this should work for a matrix field (called imageLinkBoxes) that contains only one type of block (imageLinkBox) that has 3 fields (imageLinkBox.linkText, imageLinkBox.linkUrl and imageLinkBox.text)

{% set aboutInfo = entry.imageLinkBoxes %} {# get all the blocks in the matrix #}

{% if aboutInfo|length %} {# check we have at least one block in the matrix #}

    {% set infoGrouped = aboutInfo|batch(3) %} {# group them in groups of 3 blocks #}

    {% for group in infoGrouped %}  {# loop through all the groups #}

        {% set row = 'row--' ~ loop.index %} {# set the class #}

        &lt;div class="row {{ row }}"&gt; {# open the row #}

        {% for block in group %} {# loop through all the blocks in current group #}

            &lt;div class="span4"&gt;
                &lt;div class="icon-box-2"&gt;    
                    &lt;i class="ifc-tv_show"&gt;&lt;/i&gt;
                    &lt;div class="icon-box-content"&gt;
                        &lt;h3 class="text-uppercase text-center"&gt;
                            &lt;a href="{{ block.linkUrl }}"&gt;{{ block.linkText }}&lt;/a&gt; 
                        &lt;/h3&gt;
                        &lt;p&gt;{{ block.text }}&lt;/p&gt;
                    &lt;/div&gt;  
                &lt;/div&gt;
               &lt;!-- /.icon-box-2 --&gt;               
            &lt;/div&gt;
            &lt;!-- /.span4--&gt;

        {% endfor %}

        &lt;/div&gt; {# close the row #}
        &lt;!-- /.row--&gt;

    {% endfor %}

{% endif %}


If for some reason you have more than one type of block in the matrix, then you would need to do a change:

Replace:

{% set aboutInfo = entry.imageLinkBoxes %}


With:

{% set aboutInfo = entry.imageLinkBoxes.type('imageLinkBox') %}


That would filter the blocks to only those of the type imageLinkBox.