Check if a field a included in a Matrix block 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?
In certain cases Twig is unable to recognize the correct object oriented syntax with magic properties so {% if object.property is defined %} will still produce an error.

You can use {% if block['backgroundColor'] is defined %} it seems strange and would usually considered as wrong syntax (PHP wise) but it works in Twig