<p>It's actually quite simple! What you're looking for is <a href="http://twig.sensiolabs.org/doc/filters/batch.html" rel="noreferrer">Twig's <code>batch</code> filter...</a> Ironically, the example given on that page is nearly identical to what you are requesting.</p>

<p>I've adapted the example to more closely match what you're looking for:</p>

<pre><code>{% set myData = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %}

{% for column in myData|batch(3, 'No item') %}
    &lt;div class="medium-3 medium-offset-2 small-centered medium-uncentered columns"&gt;
        &lt;ul&gt;
            {% for item in column %}
                &lt;li&gt;{{ item }}&lt;/li&gt;
            {% endfor %}
        &lt;/ul&gt;
    &lt;/div&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-05-28T18:38:49.343Z
Thanks Lindsey, I did see that, however this will create multiple columns with ONLY three list items in that column. What I actually need is ONLY three columns at the most that can divide up the amount of list items
ninjaroll
CC BY-SA 3.0
2015-06-19T14:14:55.063Z
With a little addition to the solution of Lindsey you can achieve this. Instead of using a fixed value "3" for the batch you could calculate the size of each list before.

    {% set loopLength = myData|length % 3 %}

    {% for column in myData|batch(loopLength, 'No item') %}
Pascal Mollet
CC BY-SA 3.0
2018-01-18T10:46:14.670Z
@PascalMollet This worked like a charm for me! But instead i divided the array by the number of columns I wanted, instead of using %
Jason Mayo
CC BY-SA 3.0
2015-05-28T03:45:19.080Z
2015-05-28T03:45:19.080Z
Lindsey D
<p>I'm building out my first Craft site and learning a whole lot so far. Coming from ExpressionEngine, this really seems like what EE should have been. </p>

<p>Anyway, I'm trying to find a way divide up content from a table field into three even columns. For example, if I have content in 9 rows in a table, I would like to have 3 items per column. Is this possible with Twig?  Here is the HTML.  Thank you!</p>

<pre><code>&lt;div class="medium-3 medium-offset-2 small-centered medium-uncentered columns"&gt;
    &lt;ul&gt;
        &lt;li&gt;item&lt;/li&gt;
        &lt;li&gt;item&lt;/li&gt;
        &lt;li&gt;item&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;

&lt;div class="medium-3 medium-offset-2 small-centered medium-uncentered columns"&gt;
    &lt;ul&gt;
        &lt;li&gt;item&lt;/li&gt;
        &lt;li&gt;item&lt;/li&gt;
        &lt;li&gt;item&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;

&lt;div class="medium-3 medium-offset-2 small-centered medium-uncentered columns"&gt;
    &lt;ul&gt;
        &lt;li&gt;item&lt;/li&gt;
        &lt;li&gt;item&lt;/li&gt;
        &lt;li&gt;item&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;
</code></pre>

<table-field>
Evenly dividing up table items in columns
# Evenly dividing up table items in columns

(Asked by: username_0 on 2015-05-27)

I'm building out my first Craft site and learning a whole lot so far. Coming from ExpressionEngine, this really seems like what EE should have been. 
Anyway, I'm trying to find a way divide up content from a table field into three even columns. For example, if I have content in 9 rows in a table, I would like to have 3 items per column. Is this possible with Twig?  Here is the HTML.  Thank you!

    
        item
        item
        item
    



    
        item
        item
        item
    



    
        item
        item
        item

**Tags:** table-field

---

## 1 answers

### Answer by username_1 on 2015-05-28. Score: 7

It's actually quite simple! What you're looking for is Twig's batch filter... Ironically, the example given on that page is nearly identical to what you are requesting.
I've adapted the example to more closely match what you're looking for:
{% set myData = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %}

{% for column in myData|batch(3, 'No item') %}
    
        
            {% for item in column %}
                {{ item }}
            {% endfor %}
        
    
{% endfor %}

> **Comments:**
> **username_0**: Thanks Lindsey, I did see that, however this will create multiple columns with ONLY three list items in that column. What I actually need is ONLY three columns at the most that can divide up the amount of list items  
> **username_2**: With a little addition to the solution of Lindsey you can achieve this. Instead of using a fixed value "3" for the batch you could calculate the size of each list before.      {% set loopLength = myData|length % 3 %}      {% for column in myData|batch(loopLength, 'No item') %}  
> **username_3**: @PascalMollet This worked like a charm for me! But instead i divided the array by the number of columns I wanted, instead of using %  

---

