<p>You were so close! Instead of asking whether <code>entry.type</code> is equal to the array (which it isn't), you need to find out whether the value of <code>entry.type</code> matches one of the array items.</p>

<p>Here is an updated snippet that should work for you:</p>

<pre><code>{% if entry.type == 'overview' %}
    {{ entry.title }}
{% elseif entry.type.handle in ['availability', 'specifications', 'sitemap', 'location'] %}
    {{ entry.title }}
{% else %}
    {{ entry.title }}
{% endif %}
</code></pre>

<hr>

<p><strong>EDIT:</strong></p>

<p>It's important to recognize that <code>entry.type</code> is actually an <em>object</em>. When checking a value using <code>in</code>, the object's <code>__toString</code> method will not be invoked. Therefore you'll need explicitly specify <code>entry.type.handle</code> when testing whether the type is <code>in</code> an array.</p>

CC BY-SA 4.0
2017-09-12T15:31:12.743Z
2019-02-10T04:03:32.553Z
2019-02-10T04:03:32.553Z
Jake Dohm
<p>Maybe off topic, but if you are looking to have a lot of logic based around entry types, maybe its easier to have one template per entry type?</p>

<p>If you set your section to use the template "sectionName/_entry", that entry can contain the code:</p>

<pre><code>{% include['sectionName/' ~ entry.type, 'sectionName/default'] %}
</code></pre>

<p>This way you can have a template per entry type, with a fallback to default.twig inside the "sectionName" folder (inside your template folder).</p>

<p>Now you could have a overview.twig and sitemap.twig etc.</p>

CC BY-SA 3.0
2017-09-12T15:46:46.430Z
2017-09-12T15:46:46.430Z
Syversen
<p>Is it possible to do the following?</p>

<pre><code>{% if entry.type == 'overview' %}

    {{ entry.title }}

{% elseif entry.type == ['availability', 'specifications', 'sitemap', 'location'] %}

    {{ entry.title }}

{% else %}

    {{ entry.title }}

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

<p>At the minute it is not returning anything inside the elseif, can anyone spot anything wrong with the logic or is there an alternative method?</p>

<conditional><entry-type>
If multiple entry types?
# If multiple entry types?

(Asked by: username_0 on 2017-09-12)

Is it possible to do the following?
{% if entry.type == 'overview' %}

    {{ entry.title }}

{% elseif entry.type == ['availability', 'specifications', 'sitemap', 'location'] %}

    {{ entry.title }}

{% else %}

    {{ entry.title }}

{% endif %}

At the minute it is not returning anything inside the elseif, can anyone spot anything wrong with the logic or is there an alternative method?

**Tags:** conditional, entry-type

---

## 2 answers

### Answer by username_1 on 2017-09-12. Score: 3 | Accepted answer

You were so close! Instead of asking whether entry.type is equal to the array (which it isn't), you need to find out whether the value of entry.type matches one of the array items.
Here is an updated snippet that should work for you:
{% if entry.type == 'overview' %}
    {{ entry.title }}
{% elseif entry.type.handle in ['availability', 'specifications', 'sitemap', 'location'] %}
    {{ entry.title }}
{% else %}
    {{ entry.title }}
{% endif %}


EDIT:
It's important to recognize that entry.type is actually an object. When checking a value using in, the object's __toString method will not be invoked. Therefore you'll need explicitly specify entry.type.handle when testing whether the type is in an array.


---

### Answer by username_2 on 2017-09-12. Score: 2

Maybe off topic, but if you are looking to have a lot of logic based around entry types, maybe its easier to have one template per entry type?
If you set your section to use the template "sectionName/_entry", that entry can contain the code:
{% include['sectionName/' ~ entry.type, 'sectionName/default'] %}

This way you can have a template per entry type, with a fallback to default.twig inside the "sectionName" folder (inside your template folder).
Now you could have a overview.twig and sitemap.twig etc.


---

