How is file selection handled by the Kirby pros

I’m really trying to love Kirby / I’m really trying to leave Wordpress + ACF, but I’m hitting these very common user cases that Kirby just doesn’t seem to handle as well as other systems. Where’s the file field?

For example, the client needs to include a form (a pdf) on their website. do i make them add the file to the side column then drag and drop it somewhere or do i offer them a single field that allows them to select and/or upload the file which i then use to include a link in the template. the latter is easy for the client so that’s what i want to do.

i understand there are plugins that allow this, but how would i achieve this without relying on a plugin?

The method of dragging and dropping a file into a form field always creates a kirby tag, in case of a file it looks like this

(file: companysecrets.pdf)

This is best used if you want to include a link to a file within a textarea field.

If you want a special field for a file, you should really use a select that queries the page’s files and include the link via the template.

Here’s an example blueprint section:

fields:
  pdffile:
    label: PDF file
    type: select
    options: files

This will offer all uploaded files of the page and then store the filename in the pdffile field. You can get the file object by using $page->file($page->pdffile()) in your template.

1 Like

thanks for the replies.

yeah… this is okay but a single file field is still better. there are two steps the client will need to take with this approach opposed to the file field i’m used to offering.

so can we filter what files appear in this select field type (e.g. only show .pdf files)?

No, you cannot limit the options to pdf files, but you could limit them to “documents”, at least.

fields:
  pdffile:
    label: PDF file
    type: select
    options: documents

You could, however, create your own custom select field, which then filters for pdf files only.

And create an issue with a feature request on GitHub. :grinning:

1 Like

very cool. yep. that works. with a little instruction (help) i can tell them to add a file over there and select the file here. not as good as it could be but not bad at all. thanks.

Yeah it’s been bugging me a bit since I discovered Kirby :slight_smile: In the upcoming 2.2 we’ll be able to drag files directly on the edit page and they’ll be added to the sidebar, so that will save a few clicks (see the demo video at around 2:45). On the other hand, now you can’t write a file field with it’s own drag and drop anymore, it would interfere with Kirby’s one :smiley:

It always seemed to me a way to easily qualify files was missing. Let’s say you want the users to select files for a slider, among other files. What’s the best way?
Filtering options are very basic, I can narrow it to images only, but what if there are other images that shouldn’t be used for the slider?
I could ask for specific filenames, but it puts the burden on the user.
I could make the slider a separate page, but users often find it more practical to edit a page in a single screen.
The visual selector is a good way to choose images, but you still need to check the files you want to use one by one after upload.

In this context it indeed seems easier, faster, more intuitive to just drag files to a “slider” field. One single operation and you’re done.
But then would it also add the files to the the sidebar? I’d say yes, as the sidebar shows every file attached to the page. Then what happens if a file is deleted from the field, does it stay in the sidebar? Perhaps it can become a bit confusing.

Sidebar and fields are completely separate. The sidebar shows files that are stored with the page, the fields show whatever information.

I think the best way to do this is to implement a field that takes files from the sidebar by dragging them from the sidebar to the field. You would only have to drop them somewhere on the page to upload them and then drag them to the field. This makes clear that the files are part of the page now, not part of the field.

Is this suggested type of field - a field that allows you to drag one or many files from the side column - available?

And I’m not referring to any form of wysiwyg. I’m more of an advocate of restricting the user to fixed fields which make up the page. Craft’s matrix field or AFC’s flexible field are the ultimate goal but I’m starting small here. I simply need a way to make selecting specific images possible without jumping through hoops.

No, unfortunately, there is no such field.

I have created a feature request issue on GitHub for this: https://github.com/getkirby/panel/issues/581