1

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

2

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

  • 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 Dec 3 '17 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.