<p>When you do:</p>

<pre><code>entry.type('entryTypeHandleA')
</code></pre>

<p>What you're given is an instance of an <a href="http://buildwithcraft.com/classreference/models/EntryTypeModel" rel="nofollow">EntryTypeModel</a>.</p>

<p>So when you do:</p>

<pre><code>entry.type('entryTypeHandleA')|length
</code></pre>

<p>EntryTypeModel's <code>__toString()</code> method will be called, which returns the handle of the entry type ('entryTypeHandleA') and <code>|length</code> tells you how long that handle is (16 characters).</p>

<p>So essentially what you're saying is:</p>

<pre><code>{% if 16 &gt; 0 %}
</code></pre>

<p>Which is always true.</p>

<p>However, I'm still not clear exactly what you're trying to compare against.</p>

<p>If you're just looking to see if the handle of an entry type is equal to something, then you'd use this:</p>

<pre><code>{% if entry.type.handle == 'entryTypeHandleA' %}
    a
{% elseif entry.type.handle == 'entryTypeHandleB' %}
    b
{% endif %}  
</code></pre>

CC BY-SA 3.0
2015-04-09T15:38:11.483Z
"If you're just looking to see if the handle of an entry type is equal to something, then you'd use this" is what I was expecting. I had not idea that element `handle` exists in the Craft. Big thank you for clarification  all these facts @Brad Bell.
Dominik Krulak
CC BY-SA 3.0
2015-04-09T15:27:39.653Z
2015-04-09T15:27:39.653Z
Brad Bell
<p>I have this simple the loop, and want to assign a unique code, if condition is met.</p>

<pre><code>{% paginate craft.entries.section().type().limit(20) as entriesOnPage %}    

{% for entry in entriesOnPage %}

{{ entry.type.name }}    

     {% if entry.type('entryTypeHandleA')|length &gt; 0 %}
          a
     {% elseif entry.type('entryTypeHandleB')|length &gt; 0 %}
          b
     {% endif %}  
{% endfor %}
</code></pre>

<p>This code snippet is the last try, I've tried. I always get printed the first condition, even if it's <code>false</code>. Without filter <code>length</code>, I got printed both conditions. 
I'm assuming, that it's ECM that will always exists, so that's why I never get falsey return? </p>

CC BY-SA 3.0
2015-04-09T14:52:01.723Z
Is 'news' and 'article' the handle for the entry type? Are you just meaning to check if you're on a particular entry type like `{% if entry.type.name == 'news' %}`?
Brad Bell
CC BY-SA 3.0
2015-04-09T15:03:21.990Z
Yes, so I updated the question with more clear handles. And yes. So in for the loop, if entry have `entryTypeHandleA`, I can assign an image with `entryTypeHandleA`'s name
Dominik Krulak
<entry-type>
Evaluating the if statement in entryType
# Evaluating the if statement in entryType

(Asked by: username_0 on 2015-04-09)

I have this simple the loop, and want to assign a unique code, if condition is met.
{% paginate craft.entries.section().type().limit(20) as entriesOnPage %}    

{% for entry in entriesOnPage %}

{{ entry.type.name }}    

     {% if entry.type('entryTypeHandleA')|length > 0 %}
          a
     {% elseif entry.type('entryTypeHandleB')|length > 0 %}
          b
     {% endif %}  
{% endfor %}

This code snippet is the last try, I've tried. I always get printed the first condition, even if it's false. Without filter length, I got printed both conditions. 
I'm assuming, that it's ECM that will always exists, so that's why I never get falsey return?

**Tags:** entry-type

> **Comments:**
> **username_1**: Is 'news' and 'article' the handle for the entry type? Are you just meaning to check if you're on a particular entry type like `{% if entry.type.name == 'news' %}`?  
> **username_0**: Yes, so I updated the question with more clear handles. And yes. So in for the loop, if entry have `entryTypeHandleA`, I can assign an image with `entryTypeHandleA`'s name  

---

## 1 answers

### Answer by username_1 on 2015-04-09. Score: 3 | Accepted answer

When you do:
entry.type('entryTypeHandleA')

What you're given is an instance of an EntryTypeModel.
So when you do:
entry.type('entryTypeHandleA')|length

EntryTypeModel's __toString() method will be called, which returns the handle of the entry type ('entryTypeHandleA') and |length tells you how long that handle is (16 characters).
So essentially what you're saying is:
{% if 16 > 0 %}

Which is always true.
However, I'm still not clear exactly what you're trying to compare against.
If you're just looking to see if the handle of an entry type is equal to something, then you'd use this:
{% if entry.type.handle == 'entryTypeHandleA' %}
    a
{% elseif entry.type.handle == 'entryTypeHandleB' %}
    b
{% endif %}

> **Comments:**
> **username_0**: "If you're just looking to see if the handle of an entry type is equal to something, then you'd use this" is what I was expecting. I had not idea that element `handle` exists in the Craft. Big thank you for clarification  all these facts @username_1.  

---

