0

So I have a query to return series. At the same time I eager load the series client.

{% set series = craft.entries()
    .section('series')
    .inArchive(false)
    .with('client')
    .collect()
%}

Now when I dump and die I see all my series correctly, including the eager loaded client.

And when I dump the needed value from the client:

{{dd(serie.client.0.title)}}

The needed value is returned:

^ "Title"

But when I output the value through:

{{serie.client.0.title}}

Than I get the following error:

Error: Method name must be a string

I cannot find a way to output the value. Do you see what I'm missing? Thanks in advance.

1 Answer 1

0

The reason that you get that error is probably you have some of serie that doens't has client, so during the loop you need to check whether the serie has client or not, kind of like this:

{% if serie.client|length %}
        {{serie.client.0.title}}
{% endif %}
2
  • Of course, I guess my brain stopped working. Taking some R&R. Thank you aodihis. Commented Sep 2, 2022 at 7:34
  • Ryan Irelan and Andrew Welch also kindly reacted to my question on their livestream. As suggested I could use the Collection methods for a more proper form which would result in this: {{serie.client.first().title}} Commented Sep 5, 2022 at 10:34

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.