toFile or not toFile?

In the dashboard, I want to list category pages with cover images of their latest posts. If defined, I look for the cover image, if not I take the first one available. Here’s how:

site.yml:

        image:
          query: page.children.listed.last.cover.toFile ?? page.children.listed.last.images.first
                                                ^^^^^^^

post.yml:

Cover: - file://anJ8qVtKZK7JQ8eJ

This works for one kind of template. For another kind of template .toFile must be omitted to make it work.

How’s that?

If you have a model method cover somewhere (like in the Starterkit), that already return a file object from the field, then you have to omit it.

:face_with_diagonal_mouth: Thanks a lot! That’s it. Starterkit is killing me.