Situation: I have a matrix with about 10 block types, 3 of which have a certain field. I want to check if the current block has that field.
The field in question is a dropdown with values in all 3 options.
I've tried:
{{ attribute(block, 'backgroundColor') is defined ? 'true' : 'false' }}
=> returns true for all blocks
{% if block.backgroundColor|length %}
=> errors out with Craft\MatrixBlockModel and its behaviors do not have a method or closure named "backgroundColor".
{% if block.backgroundColor is defined %}
=> same error as above
Anyone know how to do this?
{% if block['backgroundColor'] is defined %}this might not make any sense since it's actually "wrong" (PHP wise) but Twig has a rare bug in certain cases and doesn't recognize the correct syntax properly – Robin Schambach Jun 04 '18 at 22:31