<p>I would go with Twigs <a href="http://twig.sensiolabs.org/doc/filters/batch.html" rel="nofollow"><code>batch</code></a> filter, which exactly solves your problem.</p>

<p>Here an an adapted example:</p>

<pre><code>{% set items = craft.entries({
    section: 'events',
    level: 2
}).find() %}

{% for row in items|batch(2, 'No item') %}
    &lt;div class="row"&gt;
        {% for item in row %}
            {# Your entry #}
        {% endfor %}
    &lt;/div&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-09-30T14:21:55.707Z
Thx! Almost there.. Alas this outputs the content of my structure level1 n times. Can't figure out what i'm doing wrong.
eek-a-edge
CC BY-SA 3.0
2014-09-30T14:37:16.640Z
I changed my example slightly to get the entries you ask for. Not tested, but I think this should work. You could also solve it with chaining `{% set items = craft.entries.section('events').level(2).find() %}`.
Pascal Mollet
CC BY-SA 3.0
2014-09-30T15:03:54.603Z
No matter how i try to chain it, it keeps giving me the content of the parent. The number of the items is right but not the content. When i wrote `{% for entry in craft.entries.find({section:'events' ,level: 2 }) %}` the output was fine but then i couldn't do an output in batch.
eek-a-edge
CC BY-SA 3.0
2014-09-30T15:22:31.573Z
My bad > i never changed my output code to the new function name. Stupid beginners mistake. thank You much for your help!
eek-a-edge
CC BY-SA 3.0
2014-09-30T14:03:27.353Z
2014-09-30T14:34:02.370Z
2014-09-30T14:34:02.370Z
Pascal Mollet
<p>how can i output my content in pairs?</p>

<p>like this:</p>

<pre><code>div.row &gt;   entry 1 + entry 2
div.row &gt;   entry 3 + entry 4
div.row &gt;   entry 5 + entry 6
</code></pre>

<p>so far i have the following</p>

<pre><code>{% for entry in craft.entries.find({section:'events' ,level: 2 }) %}
&lt;div class="row"&gt;

    {% if loop.index0 is divisible by(2) %}
    (entry odd output here)
    {% endif %}

    {% if loop.index is divisible by(2) %}
    (entry even output here)
    {% endif %}

&lt;/div&gt;
{% endfor %}
</code></pre>

<p>but this just gives me a new row for each entry.
What's the best approach?</p>

<forloop>
How can i output my content in pairs?
# How can i output my content in pairs?

(Asked by: username_0 on 2014-09-30)

how can i output my content in pairs?
like this:
div.row >   entry 1 + entry 2
div.row >   entry 3 + entry 4
div.row >   entry 5 + entry 6

so far i have the following
{% for entry in craft.entries.find({section:'events' ,level: 2 }) %}


    {% if loop.index0 is divisible by(2) %}
    (entry odd output here)
    {% endif %}

    {% if loop.index is divisible by(2) %}
    (entry even output here)
    {% endif %}


{% endfor %}

but this just gives me a new row for each entry.
What's the best approach?

**Tags:** forloop


---

## 1 answers

### Answer by username_1 on 2014-09-30. Score: 3 | Accepted answer

I would go with Twigs batch filter, which exactly solves your problem.
Here an an adapted example:
{% set items = craft.entries({
    section: 'events',
    level: 2
}).find() %}

{% for row in items|batch(2, 'No item') %}
    
        {% for item in row %}
            {# Your entry #}
        {% endfor %}
    
{% endfor %}

> **Comments:**
> **username_0**: Thx! Almost there.. Alas this outputs the content of my structure level1 n times. Can't figure out what i'm doing wrong.  
> **username_1**: I changed my example slightly to get the entries you ask for. Not tested, but I think this should work. You could also solve it with chaining `{% set items = craft.entries.section('events').level(2).find() %}`.  
> **username_0**: No matter how i try to chain it, it keeps giving me the content of the parent. The number of the items is right but not the content. When i wrote `{% for entry in craft.entries.find({section:'events' ,level: 2 }) %}` the output was fine but then i couldn't do an output in batch.  
> **username_0**: My bad > i never changed my output code to the new function name. Stupid beginners mistake. thank You much for your help!  

---

