Files list of existing files with the ability to exclude unwanted items

Hallo,

Im trying to find a way to have a files field which would list all existing files within a pages folder. Similar to how the files filed in a page preset behaves, but with the ability to exclude unwanted files.

Files field

fields:
    attachments:
        type: files
        query: page.files.not(page.header.toFile)

Using files field doesn’t show existing files within the folder. Files can be selected or uploaded, but that’s not what im aiming for.

Apart of that, newly uploaded files from textarea do not show up in that field.

Files preset

files:
    preset: files
    query: page.files.not(page.header.toFile)

Behaves exactly like files filed. Neither existing files nor newly uploaded files from textarea show up here.

Files section

Using files section seem not a right way either, since it doesn’t support querying

Page preset

title: Page
preset: page
pages: false
fields:
  text:
    label: Content
    type: textarea
sidebar:
  meta:
    type: fields
    fields:
      date:
        label: Publish Date
        type: date
      header:
        label: Header Image
        type: files
        multiple: false
        query: page.images
        layout: cards
        image:
          cover: true
  files:
    query: page.files.not(page.header.toFile)

The files field works as expected. All existing files are shown and uploaded files from texarea are showing up in the list, however I can not filter the list in order to exclude unwanted items :confused:


Question

What is the way to have a list of files behaving as the files in page preset with the ability to filter the shown items?

Thank you in advance.

Kind regards
GDS

A files field is basically a (multi)select field for files, there is no way this field would display all existing files automatically.

Therefore, a files section would actually be the right approach, and you would add assign a (differnt) template at upload to filter them from other files you use in the page that you assign different templates to.

That would also enable you to query those files by template in the frontend.

There is also the files display section plugin which would allow you to query files (but then not upload to this section):

This sound interesting, but unfortunately I can’t find anything on the topic.

Could you point me to how to assign a template when uploading a file from textarea and files section please.

Files section: Files section | Kirby CMS
Files field: Files | Kirby CMS
Textarea: Textarea | Kirby CMS

1 Like

Thank you!