<p>It feels like not all your <code>products</code> have a <code>fieldPropertiesCategory</code> value defined. Does that work?</p>

<pre><code>{% set products = craft.entries.descendantOf(entry).all() %}
{% for product in products %}
    {% set properties = product.fieldPropertiesCategory.one() %}
    {{ properties ? properties.propCatFieldColor : '' }}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2020-03-31T06:25:51.733Z
I really like your feelings, Brad! :) I didn't had the iteration in mind. So clear now: I "configured" only my first product yet. The error was related to the products with no category selected. THANK YOU SO MUCH!!!
amkdev
CC BY-SA 4.0
2020-03-30T11:00:51.690Z
2020-03-30T11:00:51.690Z
Oli
<p>First question - but I think this is a bug (not my fault). </p>

<p>I have entries/pages (a structure) - one parent (product overview) with children (products)</p>

<p>I have one category group with categories - only for assigning some repeating data to the child entries (like properties of products - colors for instance)</p>

<p>Getting the properties (the field data of the assigned category) on the product pages itself works flawless like this: </p>

<pre><code>{% set properties = entry.fieldPropertiesCategory.one() %}
{{ properties.propCatFieldColor }}
</code></pre>

<p>BUT on my product's list page (the above-mentioned parent) it doesn't. 
I try the following:</p>

<pre><code>{% set products = craft.entries.descendantOf(entry).all() %}
{% for product in products %}
    {% set properties = product.fieldPropertiesCategory.one() %}
    {{ properties.propCatFieldColor }}
{% endfor %}
</code></pre>

<p>I get "Impossible to access an attribute ("propCatFieldColor") on a null variable."</p>

<p>But properties isn't null (checked this with dump()) ... it's the same like on the children entries. </p>

<p>My workaround is the use of all() and an additional iteration - this surprisingly works: </p>

<pre><code> {% 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 %}
</code></pre>

<p>Makes no sense to me ...</p>

<p>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.</p>

<p>Has anyone an idea on this?</p>

<templating><entry><field><category>
Impossible to access an attribute on a null variable - on the one() method - all() works!
# Impossible to access an attribute on a null variable - on the one() method - all() works!

(Asked by: username_0 on 2020-03-30)

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?

**Tags:** templating, entry, field, category


---

## 1 answers

### Answer by username_1 on 2020-03-30. Score: 1

It feels like not all your products have a fieldPropertiesCategory value defined. Does that work?
{% set products = craft.entries.descendantOf(entry).all() %}
{% for product in products %}
    {% set properties = product.fieldPropertiesCategory.one() %}
    {{ properties ? properties.propCatFieldColor : '' }}
{% endfor %}

> **Comments:**
> **username_0**: I really like your feelings, Brad! :) I didn't had the iteration in mind. So clear now: I "configured" only my first product yet. The error was related to the products with no category selected. THANK YOU SO MUCH!!!  

---

