<p>Your <code>pageType</code> variable isn’t a string, but an entry type model (i.e. an object). When treated as a string, Craft renders the entry type handle automatically as a convenience, but in other cases - like in comparisons such as this - you should use the <code>handle</code> attribute:</p>
<pre><code>{% set pageType = entry.type.handle %}
</code></pre>

CC BY-SA 4.0
2022-03-02T19:34:23.147Z
AHA the convenience! cheers
joomkit
CC BY-SA 4.0
2022-03-02T18:39:28.907Z
2022-03-02T18:39:28.907Z
Mats Mikkel Rummelhoff
<p>I am trying to get an entry type check on an array</p>
<pre><code>    {% set landerArray = ['fundingLander','healthLander', 'projectLander', 'publicationLander'] %}
    {% set pageType = entry.type %}
    {% if pageType in landerArray %}
    &lt;p&gt; lander page&lt;/p&gt;
    {% else %}
    &lt;p&gt;not lander&lt;/p&gt;
    {% endif %}
</code></pre>
<p>If I use plain text</p>
<pre><code>{% if 'fundingLander' in landerArray %}
</code></pre>
<p>It works, but if pass a variable in i get nothing.
I'm guessing twig thinks that pageType is not a string?</p>

<templating><array>
Twig in array not working as expected
# Twig in array not working as expected

(Asked by: username_0 on 2022-03-02)

I am trying to get an entry type check on an array
    {% set landerArray = ['fundingLander','healthLander', 'projectLander', 'publicationLander'] %}
    {% set pageType = entry.type %}
    {% if pageType in landerArray %}
     lander page
    {% else %}
    not lander
    {% endif %}

If I use plain text
{% if 'fundingLander' in landerArray %}

It works, but if pass a variable in i get nothing.
I'm guessing twig thinks that pageType is not a string?

**Tags:** templating, array


---

## 1 answers

### Answer by username_1 on 2022-03-02. Score: 2 | Accepted answer

Your pageType variable isn’t a string, but an entry type model (i.e. an object). When treated as a string, Craft renders the entry type handle automatically as a convenience, but in other cases - like in comparisons such as this - you should use the handle attribute:
{% set pageType = entry.type.handle %}

> **Comments:**
> **username_0**: AHA the convenience! cheers  

---

