1

When trying to query a specific single entry in a section I get back a result but all the fields inside that result are nulled.

This

{% set kundenmeinungen = craft.entries.section('unterseiten').slug('kundenmeinungen').one() %}

{{ dump(kundenmeinungen) }}

returns multiple fields that all look like this even though there is content inside the cms:

["seitenContent"]=> NULL

Any ideas?

6
  • What happens if you call dump(kundenmeinung.seitenContent)? Do you have more than one site configured?
    – Johannes
    Commented Jun 3, 2021 at 15:17
  • @Johannes you saved me. I got it working by using this: {% set kundenmeinungen = craft.entries.section('unterseiten').slug('kundenmeinungen').one() %} {{ dump(kundenmeinungen.seitenContent.type('textbewertungMitBild').all()) }}
    – Kris
    Commented Jun 3, 2021 at 16:03
  • Looks like seitenContent is not a trivial field type but maybe a matrix field?
    – Johannes
    Commented Jun 3, 2021 at 16:05
  • @Johannes yes it was a matrix field. All the other fields were easy to get but the matrix field not. I struggled for hours with this.
    – Kris
    Commented Jun 3, 2021 at 16:07
  • Oh crap, hours? Well, don't hesitate to create questions here. Also, have a look at the Craft Discord server.
    – Johannes
    Commented Jun 3, 2021 at 16:13

1 Answer 1

1

Assuming seitenContent is a matrix field, here's why it returns a null value: If you query for an entry all trivial fields are loaded right away, however non-trivial fields types like matrix, entry, asset and so on are only loaded if they are actually accessed in the Twig template (lazy loading). This is why {{ dump(kundenmeinungen) }} shows a null value on that field.

PS: If you would eager load that matrix field it would show the actual content in the dump command. To eager load a relational field you would do something like this:

{% set kundenmeinungen = craft.entries.section('unterseiten').slug('kundenmeinungen').with(['seitenContent']).one() %}

Note that kundenmeinungen.seitenContent is an array then. You have to access it like kundenmeinungen.seitenContent[0].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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