<p>This is a weird twig behavior. You have to do <code>if   stRow['caption'] is defined</code> to make it work because of the object syntax of twig.</p>

<p>Sometimes the if defined statement becomes true when you don't use the array syntax </p>

CC BY-SA 3.0
2017-12-03T22:29:14.610Z
Huh... weird. That totally fixed it. Thanks Robin! That's a fairly specific little piece of knowledge that should probably be really up front in the docs. Thanks for your help.
JamesNZ
CC BY-SA 3.0
2017-11-30T04:49:19.567Z
2017-11-30T04:49:19.567Z
Robin Schambach
<p>Why is it that in the below, referencing stRow.caption causes an error despite being wrapped in an "if defined" check?</p>

<p>The error is: </p>

<blockquote>
  <p>Craft\SuperTable_BlockModel and its behaviors do not have a method or
  closure named "caption".</p>
</blockquote>

<p>I have to be doing something so catastrophically dumb that it's not sticking out yeah?</p>

<hr>

<pre><code>{% if stRow.caption is defined %}
    {% set caption = stRow.caption %} &lt;&lt;- This line causes the error
{% endif %}
</code></pre>

<p>Same with using a null coelescing operator or a ternary operand.</p>

<pre><code>{{ stRow.caption ?? "" }} &lt;&lt;- This causes the error
-- or --
{{ stRow.caption is defined ? stRow.caption : "" }}  &lt;&lt;- This causes the error too!
</code></pre>

<p>All three of those should work.</p>

<p>Supertable: 1.0.4
Craft CMS: 2.6.2997</p>

CC BY-SA 3.0
2017-11-30T03:03:31.113Z
Did you try `| length` ?
hashtagerrors
<templating><conditional><plugin-supertable><defined>
Is defined conditional passing, yet causes a "do not have a method or closure named" error
# Is defined conditional passing, yet causes a "do not have a method or closure named" error

(Asked by: username_0 on 2017-11-30)

Why is it that in the below, referencing stRow.caption causes an error despite being wrapped in an "if defined" check?
The error is: 

Craft\SuperTable_BlockModel and its behaviors do not have a method or
  closure named "caption".

I have to be doing something so catastrophically dumb that it's not sticking out yeah?

{% if stRow.caption is defined %}
    {% set caption = stRow.caption %} <<- This line causes the error
{% endif %}

Same with using a null coelescing operator or a ternary operand.
{{ stRow.caption ?? "" }} <<- This causes the error
-- or --
{{ stRow.caption is defined ? stRow.caption : "" }}  <<- This causes the error too!

All three of those should work.
Supertable: 1.0.4
Craft CMS: 2.6.2997

**Tags:** templating, conditional, plugin-supertable, defined
> **Comments:**
> **username_1**: Did you try `| length` ?  

---

## 1 answers

### Answer by username_2 on 2017-11-30. Score: 2 | Accepted answer

This is a weird twig behavior. You have to do `if stRow['caption'] is defined` to make it work because of the object syntax of twig.

Sometimes the if defined statement becomes true when you don't use the array syntax

> **Comments:**
> **username_0**: Huh... weird. That totally fixed it. Thanks Robin! That's a fairly specific little piece of knowledge that should probably be really up front in the docs. Thanks for your help.  

---

