Files field select from specific files section

Hi everyone.

For a project I need the client to be able to upload images and PDF files.
Then, in a structure field, I want him to select (for each publication) an image to use as cover and a PDF for the download.

I so decided to use two different files sections, each with a different template (one with accepted mime jpg/png and the other only with pdf).

So on everything looks just fine, but…
How can I tell each files field that I want to select only from a specific file section (coverFiles or pdfFiles)?
It works with the upload but not with the selection.

Hope you understand what I mean.
See below my blueprint.

title: Flyer e brochure

columns:
  left:
    width: 2/3
    sections:

      content:
        type: fields

        fields:

          homeTitle:
            label: Titolo sulla homepage
            type: text
            help: Se il campo viene lasciato vuoto il sistema mostrerà il titolo della pagina

          flyers:
            label: Lista dei flyer e delle brochure
            type: structure
            columns:
              title:
                width: 3/4
              active:
                width: 1/4
            fields:
              title:
                label: Nome del documento
                type: text
              cover:
                label: Immagine di copertina
                type: files
                uploads: mediaCover
                multiple: false
                width: 1/2
              pdf:
                label: Documento PDF
                type: files
                uploads: pdfDocuments
                multiple: false
                width: 1/2
              active:
                label: Il flyer è attivo?
                type: toggle
                default: true

  right:
    width: 1/3
    sections:

      coverFiles:
        headline: Immagini di copertina
        type: files
        template: mediaCover

      pdfFiles:
        headline: Documenti PDF
        type: files
        template: pdfDocuments

Thanks for your help and have a nice day!
Sara

You can use the query option to limit the selection to files with a certain template: https://getkirby.com/docs/reference/panel/fields/files#querying-files

cover:
  label: Immagine di copertina
  type: files
  query: page.files.filterBy('template', 'mediaCover')
pdf:
  label: Documento PDF
  type: files
  query: page.files.filterBy('template', 'pdfDocuments')

It should also work by using page.files.template('pdfDocuments').
Didn’t test this one, though.

1 Like

Oh shit, of course!!
Sometimes I get stuck in really dumb things. :sweat_smile: :shushing_face:

Thanks a lot thguenther! :hugs:

And, by the way, the second solution works! :wink: