Understand file and image.yml

The first files thingy is a files section. It does have a template option.

The second example is a files field. A files field does not have a template option. However, you can set the template for files you upload through this field via the upload option:

image:
  type: files
  layout: cards
  upload:
     template: image

In case you have other file types in your page and you want to limit what files can be selected, you can use the query option:

image:
  type: files
  layout: cards
  query: page.images.filterBy('template', 'image')
  upload:
     template: image

Note that if you call your field image you run into conflicts with Kirby’s native image() method. If you want to call this field in your template, you would have to call it like this:

$image = $page->content()->image()->toFiles();

Therefore, consider renaming or prefixing the fieldname.

1 Like