How to select a cover image from multiple uploaded images

Hi,
quite new to Kirby 4.
I want to select a single image from multiple uploaded images to be the cover image.
That’s what I did:

I have a gallery.yml file

    sections:
      cover: 
        type: fields
        label: Bild für Frontseite
        fields:
          coverImage:
            type: files
            label: Cover
            max: 1
            template: cover
      gallery:
        label: Gallery
        type: files
        layout: cards

in my corresponding .php I try to get the cover image by

<?php if ($image = $article->files()->template('cover')->first()): ?>
<img
            alt="<?= $image->alt() ?>"
            src="<?= $image->resize(300)->url() ?>"
            ....
>

What’s going wrong?

There’s a difference between the Files Field and the Files Section.

The field stores a reference to the selected files in the page content file. The section simply shows you the already uploaded files. The configuration in the blueprint is also slightly different: important for you is that the field does not have a template option.

So, in your case no files are actually ever set to template cover.

You probably wanted to do something like this:

    sections:
      cover: 
        type: fields
        fields:
          coverImage:
            label: Bild für Frontseite
            type: files
            label: Cover
            max: 1
      gallery:
        label: Gallery
        type: files
        layout: cards
<?php if ($image = $article->coverImage()->toFile()): ?>
  <img
    alt="<?= $image->alt() ?>"
    src="<?= $image->resize(300)->url() ?>"
    ....
>

Wow, that was quick.
And exactly what I was looking for.
Thank you so much!