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
    Jun 3 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
    Jun 3 at 16:03
  • Looks like seitenContent is not a trivial field type but maybe a matrix field?
    – Johannes
    Jun 3 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
    Jun 3 at 16:07
  • Oh crap, hours? Well, don't hesitate to create questions here. Also, have a look at the Craft Discord server.
    – Johannes
    Jun 3 at 16:13
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, privacy policy and cookie policy

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