<pre><code>{% set block = entry.bodyRepeater.nth(2) %}

{% if block %}
    &lt;h3&gt;{{ block.heading }}&lt;/h3&gt;
{% endif %}
</code></pre>

<p>Craft 2.2 introduced the <a href="https://craftcms.com/docs/templating/elementcriteriamodel#nth" rel="nofollow"><code>nth</code></a> method to ElementCriteriaModel objects for fetching the element at a specific offset.
It's more convienient to use this instead of a combination of the undocumented <code>offsetExists</code> and <code>findElementAtOffset</code> methods.</p>

CC BY-SA 3.0
2016-04-19T08:41:53.757Z
2016-04-19T08:41:53.757Z
carlcs
<p>I managed to do this for a quiz, getting the row from the url</p>

<pre><code>{% set theRow = craft.request.getParam('row') %} 
{{entry.matrixField[theRow].body}}
</code></pre>

<p>Just remember zero is the first row.</p>

CC BY-SA 3.0
2016-04-19T08:41:00.523Z
`entry.matrixField[1]` queries for all the blocks, so it isn't a whole lot more efficient then the loop approach in the question.
carlcs
CC BY-SA 3.0
2016-04-14T15:38:44.843Z
2016-04-14T15:38:44.843Z
Spotd
<p>This works but using this code can be a problem if you are dealing with a huge number of rows.</p>

<p>To access the n-th row, you can use:</p>

<pre><code>{{ entry.blockRepeater.findElementAtOffset(n-1).heading }}
</code></pre>

<p>I found this method in the <code>ElementCriteriaModel</code> class. You can test if a certain row exists using <code>entry.blockRepeater.offsetExists(n)</code>.</p>

CC BY-SA 3.0
2014-07-08T12:00:39.957Z
2014-07-08T12:00:39.957Z
Mario
<p>I'm looking to be able to return the info from a field(s) from a Matrix row where I know which row I want (long story). I had a guess at various ways of doing this, but in the end the only way that worked was to run the loop with an if statement to limit the output to a given row's id, e.g:</p>

<pre><code>{% for block in entry.bodyRepeater %}
    {% if loop.index==2 %}
    &lt;h3&gt;{{ block.heading }}&lt;/h3&gt;
    {% endif %}
{% endfor %}
</code></pre>

<p>Guessing there might be a better way though?</p>

<matrix>
Return specific Matrix row?
# Return specific Matrix row?

(Asked by: username_0 on 2014-07-08)

I'm looking to be able to return the info from a field(s) from a Matrix row where I know which row I want (long story). I had a guess at various ways of doing this, but in the end the only way that worked was to run the loop with an if statement to limit the output to a given row's id, e.g:
{% for block in entry.bodyRepeater %}
    {% if loop.index==2 %}
    {{ block.heading }}
    {% endif %}
{% endfor %}

Guessing there might be a better way though?

**Tags:** matrix


---

## 3 answers

### Answer by username_3 on 2014-07-08. Score: 4 | Accepted answer

This works but using this code can be a problem if you are dealing with a huge number of rows.
To access the n-th row, you can use:
{{ entry.blockRepeater.findElementAtOffset(n-1).heading }}

I found this method in the ElementCriteriaModel class. You can test if a certain row exists using entry.blockRepeater.offsetExists(n).


---

### Answer by username_1 on 2016-04-19. Score: 3

{% set block = entry.bodyRepeater.nth(2) %}

{% if block %}
    {{ block.heading }}
{% endif %}

Craft 2.2 introduced the nth method to ElementCriteriaModel objects for fetching the element at a specific offset.
It's more convienient to use this instead of a combination of the undocumented offsetExists and findElementAtOffset methods.


---

### Answer by username_2 on 2016-04-14. Score: 0

I managed to do this for a quiz, getting the row from the url
{% set theRow = craft.request.getParam('row') %} 
{{entry.matrixField[theRow].body}}

Just remember zero is the first row.

> **Comments:**
> **username_1**: `entry.matrixField[1]` queries for all the blocks, so it isn't a whole lot more efficient then the loop approach in the question.  

---

