First question - but I think this is a bug (not my fault).
I have entries/pages (a structure) - one parent (product overview) with children (products)
I have one category group with categories - only for assigning some repeating data to the child entries (like properties of products - colors for instance)
Getting the properties (the field data of the assigned category) on the product pages itself works flawless like this:
{% set properties = entry.fieldPropertiesCategory.one() %}
{{ properties.propCatFieldColor }}
BUT on my product's list page (the above-mentioned parent) it doesn't. I try the following:
{% set products = craft.entries.descendantOf(entry).all() %}
{% for product in products %}
{% set properties = product.fieldPropertiesCategory.one() %}
{{ properties.propCatFieldColor }}
{% endfor %}
I get "Impossible to access an attribute ("propCatFieldColor") on a null variable."
But properties isn't null (checked this with dump()) ... it's the same like on the children entries.
My workaround is the use of all() and an additional iteration - this surprisingly works:
{% set products = craft.entries.descendantOf(entry).all() %}
{% for product in products %}
{% set properties = product.fieldPropertiesCategory.all() %}
{% for property in properties %}
{% if loop.first %}
{{ properties.propCatFieldColor }}
{% endif %}
{% endfor %}
{% endfor %}
Makes no sense to me ...
I tried everything - getting the category object of the children entries in various ways on the parent entry but this all doesn't work. Always the impossible to access error.
Has anyone an idea on this?