<p>I believe the code below should work. This code assumes you are on a single entry page or within a loop and your entry is available to you with the <code>entry</code> variable. You may need to adjust the <code>block.type</code> name and <code>block.employees</code> entries field name to match your proper handles. I've added comments inline to clarify each step:</p>

<pre><code>{# Loop through your Matrix Field #}
{% for block in entry.contactMatrix %}

    {# Check to see which type of block you have.  You only want to check for the employees entry field if you are within the contact block #}
    {% if block.type == 'contact' %}

        {# See if your employees entries field has more than 1 entry #}
        {% if block.employees|length &gt; 1 %}

          {# Output HTML for blocks with multiple employees #}

        {% else %}

          {# Output HTML for blocks with zero or one employee #}

        {% endif %}

    {% endif %}

{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-07-15T15:48:37.713Z
That `else` is `{# Output HTML for blocks with ZERO OR one employee #}`
Marion Newlevant
CC BY-SA 3.0
2014-07-16T11:35:13.523Z
@Oyvind could you please accept / update helpful answers to your questions?
carlcs
CC BY-SA 3.0
2014-07-15T09:23:34.940Z
2014-07-15T17:23:39.287Z
2014-07-15T17:23:39.287Z
Ben Parizek
<p>In my HTML-prototype I have two ways of showing a module of employees. One version shows one employee, and the other shows two. </p>

<p>To build this in Craft I have setup a Matrix field (with a handle named 'contactMatrix'). It contains a headline, some text and an entry field to pick employees (with a limit of two).</p>

<p>To output this in my front end I need a way to check if the user has picked one or two employees. Something like:</p>

<p>if one employee within the matrix field is chosen
<em>do this html</em>
else
if two employees within the matrix field is chosen
<em>do this slightly different html</em>
end if</p>

<p>Help, anyone? </p>

<matrix><conditional><field><entries-field>
Checking if a matrix field with entries has more than one entry
# Checking if a matrix field with entries has more than one entry

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

In my HTML-prototype I have two ways of showing a module of employees. One version shows one employee, and the other shows two.

To build this in Craft I have setup a Matrix field (with a handle named 'contactMatrix'). It contains a headline, some text and an entry field to pick employees (with a limit of two).

To output this in my front end I need a way to check if the user has picked one or two employees. Something like:

if one employee within the matrix field is chosen
*do this html*
else
if two employees within the matrix field is chosen
*do this slightly different html*
end if

Help, anyone?

**Tags:** matrix, conditional, field, entries-field


---

## 1 answers

### Answer by username_1 on 2014-07-15. Score: 4

I believe the code below should work. This code assumes you are on a single entry page or within a loop and your entry is available to you with the entry variable. You may need to adjust the block.type name and block.employees entries field name to match your proper handles. I've added comments inline to clarify each step:
{# Loop through your Matrix Field #}
{% for block in entry.contactMatrix %}

    {# Check to see which type of block you have.  You only want to check for the employees entry field if you are within the contact block #}
    {% if block.type == 'contact' %}

        {# See if your employees entries field has more than 1 entry #}
        {% if block.employees|length > 1 %}

          {# Output HTML for blocks with multiple employees #}

        {% else %}

          {# Output HTML for blocks with zero or one employee #}

        {% endif %}

    {% endif %}

{% endfor %}

> **Comments:**
> **username_2**: That `else` is `{# Output HTML for blocks with ZERO OR one employee #}`  
> **username_3**: @Oyvind could you please accept / update helpful answers to your questions?  

---

