<p>I don't know whether you've seen the <a href="https://twig.sensiolabs.org/doc/2.x/filters/batch.html" rel="nofollow noreferrer"><code>batch</code></a> Twig filter? You may find if useful to accomplish exactly what you are trying to do, but with a little bit less hassle.</p>

<p>From the example in the link above:</p>

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

&lt;table&gt;
{% for row in items|batch(3, 'No item') %}
    &lt;tr&gt;
        {% for column in row %}
            &lt;td&gt;{{ column }}&lt;/td&gt;
        {% endfor %}
    &lt;/tr&gt;
{% endfor %}
&lt;/table&gt;
</code></pre>

<p>And here's what it outputs:</p>

<pre><code>&lt;table&gt;
    &lt;tr&gt;
        &lt;td&gt;a&lt;/td&gt;
        &lt;td&gt;b&lt;/td&gt;
        &lt;td&gt;c&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;d&lt;/td&gt;
        &lt;td&gt;e&lt;/td&gt;
        &lt;td&gt;f&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;g&lt;/td&gt;
        &lt;td&gt;No item&lt;/td&gt;
        &lt;td&gt;No item&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
</code></pre>

<p>Essentially you're grouping your values into rows of a specific number (in this example it's 5). Then you can specify what to put in any empty spaces. So here it's the words 'No Item', but in your case it could be the middle partner entry.</p>

CC BY-SA 3.0
2017-06-22T07:02:22.690Z
2017-06-22T07:02:22.690Z
Steve Holland
<p>If you have a array of entries like so:</p>

<pre><code>{% set entries = craft.entires.find() %}
</code></pre>

<p>And you wanted to access the fifth item in the array (which is 0-indexed), you would do something like:</p>

<pre><code>{% set fifthEntry = entries[4] %}
</code></pre>

CC BY-SA 3.0
2017-06-21T20:47:21.177Z
2017-06-21T20:47:21.177Z
Brad Bell
<p>I'm working with a carousel that has two rows. Each item in the carousel displays an icon for a "media partner". This works all fine and dandy until there's an odd number of media partners, because then there is an extra unnecessary space in the carousel. I have the issue solved logically, but I can't figure out how to implement it into Craft. I need a way to access a certain entry plainly by its number, i.e. the fifth entry, seventh entry, ninth entry, etc. </p>

<p>There are 11 entries that I am working with, however that number may change in the future. So, first, I grab how many current entries there are in the particular field that I am looking for: </p>

<pre><code>{% set entryNum = craft.entries.section('partners').featuredMediaPartner('1') | length %}
</code></pre>

<p>This returns 11.</p>

<p>Next, this number gets divided by two, because I want to display the middle partner in the empty space that the carousel creates if there's an odd number (I already have coded to determine what to do if there's an odd number). So 11/2 = 5. How would I access the fifth entry? Thanks.</p>

<templating><entries><assets><entry><index>
Get a specific entry by its index or number?
# Get a specific entry by its index or number?

(Asked by: username_0 on 2017-06-21)

I'm working with a carousel that has two rows. Each item in the carousel displays an icon for a "media partner". This works all fine and dandy until there's an odd number of media partners, because then there is an extra unnecessary space in the carousel. I have the issue solved logically, but I can't figure out how to implement it into Craft. I need a way to access a certain entry plainly by its number, i.e. the fifth entry, seventh entry, ninth entry, etc. 
There are 11 entries that I am working with, however that number may change in the future. So, first, I grab how many current entries there are in the particular field that I am looking for: 
{% set entryNum = craft.entries.section('partners').featuredMediaPartner('1') | length %}

This returns 11.
Next, this number gets divided by two, because I want to display the middle partner in the empty space that the carousel creates if there's an odd number (I already have coded to determine what to do if there's an odd number). So 11/2 = 5. How would I access the fifth entry? Thanks.

**Tags:** templating, entries, assets, entry, index

---

## 2 answers

### Answer by username_1 on 2017-06-22. Score: 1

I don't know whether you've seen the batch Twig filter? You may find if useful to accomplish exactly what you are trying to do, but with a little bit less hassle.
From the example in the link above:
{% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %}


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


And here's what it outputs:

    
        a
        b
        c
    
    
        d
        e
        f
    
    
        g
        No item
        No item
    


Essentially you're grouping your values into rows of a specific number (in this example it's 5). Then you can specify what to put in any empty spaces. So here it's the words 'No Item', but in your case it could be the middle partner entry.


---

### Answer by username_2 on 2017-06-21. Score: 0

If you have a array of entries like so:
{% set entries = craft.entires.find() %}

And you wanted to access the fifth item in the array (which is 0-indexed), you would do something like:
{% set fifthEntry = entries[4] %}


---

