<p>When checking if a matrix block property is defined, I'm getting an error:</p>

<pre><code>Craft\EntryModel and its behaviors do not have a method or closure named "contentSource".
</code></pre>

<p>The line that is throwing this error is specifically checking if that property is defined.</p>

<pre><code>{% if block.contentSource is defined %}
    {# Stuff and things #}
{% endif %}

-- Or --

{% set theThing = block.contentSource ?? "fallback" %}
</code></pre>

<p>Am I expecting the "is defined" check to be smarter than it actually is? I can't see an example of this in the matrix field or craft twig/templating docs.</p>

<p>Thanks :)</p>

CC BY-SA 3.0
2016-12-14T22:05:38.297Z
Hey James, try `block['contentSource']` instead or test against an attribute rather than a field, e.g. `if block.type == 'foo'`.
carlcs
CC BY-SA 3.0
2016-12-14T22:06:58.663Z
See answers in the link above.
carlcs
<templating><matrix><defined>
Twig "Is defined" throwing error on matrix row EntryModel property
# Twig "Is defined" throwing error on matrix row EntryModel property

(Asked by: username_0 on 2016-12-14)

When checking if a matrix block property is defined, I'm getting an error:
Craft\EntryModel and its behaviors do not have a method or closure named "contentSource".

The line that is throwing this error is specifically checking if that property is defined.
{% if block.contentSource is defined %}
    {# Stuff and things #}
{% endif %}

-- Or --

{% set theThing = block.contentSource ?? "fallback" %}

Am I expecting the "is defined" check to be smarter than it actually is? I can't see an example of this in the matrix field or craft twig/templating docs.
Thanks :)

**Tags:** templating, matrix, defined

> **Comments:**
> **username_1**: Hey James, try `block['contentSource']` instead or test against an attribute rather than a field, e.g. `if block.type == 'foo'`.  
> **username_1**: See answers in the link above.  

---

## 0 answers

