<p>Twig has a "is defined" test that you can apply to a variable to see if it exists:</p>

<pre><code>{% if entry.possibleField is defined %}
    Yup!
{% else %}
    Nope!
{% endif %}
</code></pre>

<p>And here is <a href="http://twig.sensiolabs.org/doc/tags/if.html" rel="nofollow">more</a> information on using <code>is defined</code>.</p>

CC BY-SA 3.0
2014-06-26T16:02:07.103Z
2014-06-26T18:03:46.233Z
2014-06-26T18:03:46.233Z
Patrick Harrington
<p>I've got a generic template that can display entries from different channels. How in the template can I test if a field has been has been assigned to any given channel?</p>

CC BY-SA 3.0
2014-06-26T16:00:10.487Z
Why not check for the field's existence in an entry?
Bryan Redeagle
<field>
How can I test if a field has been assigned to a channel?
# How can I test if a field has been assigned to a channel?

(Asked by: username_0 on 2014-06-26)

I've got a generic template that can display entries from different channels. How in the template can I test if a field has been has been assigned to any given channel?

**Tags:** field

> **Comments:**
> **username_1**: Why not check for the field's existence in an entry?  

---

## 1 answers

### Answer by username_2 on 2014-06-26. Score: 8 | Accepted answer

Twig has a "is defined" test that you can apply to a variable to see if it exists:
{% if entry.possibleField is defined %}
    Yup!
{% else %}
    Nope!
{% endif %}

And here is more information on using is defined.


---

