<p>According to <a href="https://craftcms.stackexchange.com/a/2357/130">this answer</a> the only ways to filter matrix blocks are by type, or by position. So you need to use the <code>if</code> condition on the <a href="http://twig.sensiolabs.org/doc/tags/for.html" rel="nofollow noreferrer">twig for tag</a>.</p>

<pre><code>{% for m in entry.myMatrix if m.theName == nameImLookingFor %}
  {% if loop.index == 1 %}
    got the first one, it is {{m.theName}}
  {% endif %}
{% endfor %}
</code></pre>

<p>If you don't want to loop over all of the blocks, you can also install the <a href="https://github.com/marionnewlevant/craft-mnbreakandcontinue" rel="nofollow noreferrer">mnbreakandcontinue plugin</a> and break out of the loop after the first match:</p>

<pre><code>{% for m in entry.myMatrix if m.theName == nameImLookingFor %}
  got the first one, it is {{m.theName}}
  {% break %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-11-27T19:36:45.023Z
And according to Brandon's comment [here](http://craftcms.stackexchange.com/questions/39/search-matrix-for-blocks-with-upcoming-dates/41#comment5242_41), things will change with Craft 2.3! Really good news...
carlcs
CC BY-SA 3.0
2014-11-27T19:57:33.473Z
Awesome thanks! and thanks for mentioning the 'mnbreakandcontinue' plugin :)
Lea Hayes
CC BY-SA 3.0
2014-11-27T19:30:51.587Z
2014-11-27T19:30:51.587Z
2017-04-13T12:51:00.303Z
Marion Newlevant
<p>If I have a matrix field with 2 fields "Name" and "Entry" is it possible to lookup the first row in that matrix field which has a specific "Name"?</p>

<p>Context: Twig template.</p>

<templating><matrix>
Lookup row in matrix field by "Name" column?
# Lookup row in matrix field by "Name" column?

(Asked by: username_0 on 2014-11-27)

If I have a matrix field with 2 fields "Name" and "Entry" is it possible to lookup the first row in that matrix field which has a specific "Name"?

Context: Twig template.

**Tags:** templating, matrix


---

## 1 answers

### Answer by username_1 on 2014-11-27. Score: 3 | Accepted answer

According to this answer the only ways to filter matrix blocks are by type, or by position. So you need to use the if condition on the twig for tag.
{% for m in entry.myMatrix if m.theName == nameImLookingFor %}
  {% if loop.index == 1 %}
    got the first one, it is {{m.theName}}
  {% endif %}
{% endfor %}

If you don't want to loop over all of the blocks, you can also install the mnbreakandcontinue plugin and break out of the loop after the first match:
{% for m in entry.myMatrix if m.theName == nameImLookingFor %}
  got the first one, it is {{m.theName}}
  {% break %}
{% endfor %}

> **Comments:**
> **username_2**: And according to Brandon's comment [here](http://craftcms.stackexchange.com/questions/39/search-matrix-for-blocks-with-upcoming-dates/41#comment5242_41), things will change with Craft 2.3! Really good news...  
> **username_0**: Awesome thanks! and thanks for mentioning the 'mnbreakandcontinue' plugin :)  

---

