Panel Field Type for attachments like documents?

Hello,

I am fairly new to Kirby.
Is there a field type which handles attachments, like PDF?
I can’t find a proper type. I checked the Panel Field Types already.

I need to serve 1-3 documents to download (mainly PDF) for the site visitors.

There is no particular field, you can either use a select field or have a look at the Kirby selector field. Then you can server these files for download via your template.

Ive done something similar to this in the past - I would suggest putting a button next to the select that triggers the download, otherwise you end up with lots of wasted downloads because people like to play with selects.

The select field in the Panel does not trigger a download… I guess you mean in the frontend? But the question was about Panel fields.

Yes - sounded to me like they want to populate a select on the front end from a field on the backend.

For the frontend, it makes sense not to trigger a download from the select. But then, I wouldn’t use a select on the frontend, anyway. Rather an image of the cover or something more appealing.

Hello and good morning,

thank you for your replies.
What I need is for the backend to upload some files, i.E. pdf. And give those Files a proper screen name.
On the front end, in the template, I just a simple list with the screen name and the direct link to the files.

Cheers
Stefan

Ah, ok, then you don’t need a field at all, you can use the file section in the sidebar to upload files. Just make sure to allow file upload in your blueprint file settings.

files: true

Or limit filetype upload:

…
files:
    type: document

Sure, I would personally do a list on the page. A select is over completing it. My use case for the select was a site menu for mobiles, and picking from the select changed the page rather then triggering download.

@StefanG You can easily do a list on the page with file type icons (via FontAwesome) like this:

  <ul class="download--list">

  <?php foreach($page->documents()->filterBy('extension', 'pdf') as $pdf): ?>
      <li><a href="<?= $pdf->url() ?>"><i class="fa fa-file-pdf-o" aria-hidden="true"></i><?= $pdf->filename() ?> (<?= $pdf->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->documents()->filterBy('extension', 'doc') as $doc): ?>
      <li><a href="<?= $doc->url() ?>"><i class="fa fa-file-word-o" aria-hidden="true"></i><?= $doc->filename() ?> (<?= $doc->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->documents()->filterBy('extension', 'docx') as $docx): ?>
      <li><a href="<?= $docx->url() ?>"><i class="fa fa-file-word-o" aria-hidden="true"></i><?= $docx->filename() ?> (<?= $docx->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->archives()->filterBy('extension', 'zip') as $filearchive): ?>
      <li><a href="<?= $filearchive->url() ?>"><i class="fa fa-file-excel-o" aria-hidden="true"></i><?= $filearchive->filename() ?> (<?= $filearchive->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->documents()->filterBy('extension', 'xls') as $excel): ?>
      <li><a href="<?= $excel->url() ?>"><i class="fa fa-file-excel-o" aria-hidden="true"></i><?= $excel->filename() ?> (<?= $excel->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->documents()->filterBy('extension', 'xlsx') as $excelx): ?>
      <li><a href="<?= $excelx->url() ?>"><i class="fa fa-file-excel-o" aria-hidden="true"></i><?= $excelx->filename() ?> (<?= $excelx->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->images()->filterBy('extension', 'jpg') as $jpg): ?>
      <li><a href="<?= $jpg->url() ?>"><i class="fa fa-file-picture-o" aria-hidden="true"></i><?= $jpg->filename() ?> (<?= $jpg->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->images()->filterBy('extension', 'eps') as $eps): ?>
      <li><a href="<?= $eps->url() ?>"><i class="fa fa-file-picture-o" aria-hidden="true"></i><?= $eps->filename() ?> (<?= $eps->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->images()->filterBy('extension', 'psd') as $psd): ?>
      <li><a href="<?= $psd->url() ?>"><i class="fa fa-file-picture-o" aria-hidden="true"></i><?= $psd->filename() ?> (<?= $psd->niceSize() ?>)</a></li>
  <?php endforeach ?>

  <?php foreach($page->images()->filterBy('extension', 'png') as $png): ?>
      <li><a href="<?= $png->url() ?>"><i class="fa fa-file-picture-o" aria-hidden="true"></i><?= $png->filename() ?> (<?= $png->niceSize() ?>)</a></li>
  <?php endforeach ?>

  </ul>

yes, but how can I assign an readable user friendly name, like “File Name” and not the_file.pdf? I think therefore I need a field.
Kirby offers a nice overview about all attached files. You can edit them, rename the original file, an delete them. But I guess to have another form field to enter a user friendly name, like “The File”, I can call this easily in the templates.

Cheers

You can do friendly names with file metadata https://getkirby.com/docs/content/media

I don’t like to say awesome, but in this case. Awesome :slight_smile: Thank you guys for your immediately help.

Cheers
Stefan

Just one more thing, a little feedback.

I followed your instructions and created a text file appropriate to the download file (file.pdf), like you guys mentioned. Besides the fact you need to upload the file.pdf.txt manually, it worked quite well.

But, it doesn’t shows up in the file list - since this is a txt file - and is not editable within the panel. Though I stumbled across this thread and used the files blueprint instead. Now I can edit the user friendly filename within the panel. And this is quite nice.


The link above is not really for Panel users, you can find all about using the Panel blueprints and settings. permissions etc. in the Panel section of the docs, file settings are here: https://getkirby.com/docs/panel/blueprints/file-settings

You don’t have to manually create the text file. Upload the file, edit it in the panel and Kirby will create the meta file.