Skip to content

Kirby 6.0.0

Filelist

List, edit and upload files

Field options

Name Type Default Description
batch bool false Show/hide the batch select interface
blueprint string null Filters the files by blueprint and sets the blueprint for all uploads
columns array no default value Columns config for layout: table. false hides a column, a string sets its label.
create bool true Option to switch off the upload button
default mixed null Default value for the field, which will be used when a page/file/user is created
empty arrayorstring null Sets the text for the empty state box
flip bool false If true, the order of the entries is reversed
help arrayorstring null Optional help text below the field
image arrayorstringorfalse [] Image options for each entry, a query string for the preview image or false to disable previews
info arrayorstring null Info text shown next to or below the main text of each entry
label arrayorstring no default value The field label can be set as string or associative array with translations
layout string 'list' Switch the layout of the items. Available layouts: list, cardlets, cards and table
limit int 20 The number of entries that will be displayed at once. Afterwards pagination kicks in.
max int null Sets the maximum number of allowed items in the field
min int null Sets the minimum number of required entries
page int null Sets the default page for the pagination
parent string null Query for the parent model that holds the entries
query string null Filters the entries by a query. Sorting will be disabled
search bool false Enables/disables the search
size string 'auto' Size for layout: cards. Available sizes: auto, tiny, small, medium, large, huge, full
sortBy string null Sorts the entries by the given field and order (i.e. title desc) Drag & drop is disabled in this case
sortable bool true If true, entries are sortable via drag & drop
text arrayorstring '{{ file.filename }}' Setup for the main text of each entry
translate bool true Should the field be translatable?
when array null Conditions when the field will be shown
width string '1/1' The width of the field in the field grid. Available widths: 1/1, 1/2, 1/3, 1/4, 2/3, 3/4

The filelist field can be used to show any combination of files for the current page, any other page in your site or even all files of your site. Using a filelist field, you can execute the following operations on files (if not forbidden or impossible because of other settings):

  • upload files
  • replace a file
  • delete a file
  • rename a file
  • change the order number of files (if sorted manually)
  • change the template of a file

Example

/site/blueprints/pages/project.yml
title: Project

fields:
  gallery:
    label: Gallery
    type: filelist
    blueprint: gallery

A filelist stores nothing in the content file. It displays the files that already exist, so there is no value to fetch from it in your templates.

Shortcuts

For simple lists that are only used once per blueprint, you can use shortcuts. In its most basic form, a filelist field consists of the field type as name, and true as its value.

fields:

  filelist: true

This will add a filelist field with all default properties.

These shortcuts can be extended with other field properties as needed, for example:

fields:

  filelist:
    label: My Files
    blueprint: cover

Keep in mind that the same field name can only be used once per blueprint.

Label

The label will be displayed above the filelist field. You can pass a simple headline as a string or you can provide translations for multiple languages, if you have an international editing team.

Single language

label: Gallery

Multiple languages

label:
  en: Gallery
  de: Galerie
  es: Galería

Placeholders

You can inject information from the current page into the label with template placeholders using our query language.

label: "{{ page.title }} Gallery"

Upload button

You can disable the upload button in a filelist field with the create option. This is useful for query-based filelist fields where uploads wouldn't show up in the list.

files:
  type: filelist
  query: page.files
  create: false

Layout

The files can either be displayed as a simple list or as cards with preview images. The list view is the default view.

List layout (default)

The list layout is perfect for file types without thumbnails like PDFs, excel files, or any other docs. It can also be quite helpful for long galleries that would take up too much space as cards.

layout: list

Cards layout

The card layout is great for all kinds of images.

layout: cards

Cardlets layout

The cardlets layout is great for nice visual previews of files, while your text content is still representend decently.

layout: cardlets

Table layout

The table layout has the highest information density. Columns can be fully customized and make it perfect if you need to show multiple values at once for better overview and scannability.

layout: table

The table layout will show the preview image together with a title and info column based on your text and info settings. You can switch off those automatic columns with image: false, text: false and info: false if you want to introduce your own columns.

Columns

Custom table columns can be defined with the columns option.

layout: table
columns:
  alt: true
  dimensions: true

Each column can be customized with additional settings:

Label
layout: table
columns:
  alt:
    label: Alt Text
Translated label
layout: table
columns:
  alt:
    label:
      en: Alternative Text
      de: Alternativ Text
Alignment

Text alignment can be left (default), center or right.

layout: table
columns:
  dimensions:
    label: Dimensions
    align: right
Width

The column width can be set via the width property. You can use the usual fractions:

layout: table
columns:
  dimensions:
    label: Dimensions
    width: 1/6
Value

By default, the table cells contain the field value matching the column name. You can customize the value with a string template.

layout: table
columns:
  date:
    label: Date
    value: "{{ file.date.toDate('d.m.Y') }}"
HTML

Values are converted to safe HTML by default. This is the most secure way to handle content in your Panel. If you know what you are doing and you want to render HTML in a table cell, you can use the html option to stop HTML from being auto-encoded.

layout: table
columns:
  html:
    label: HTML
    html: true
    value: "{{ file.someSafeHTML }}"
Mobile

Set the mobile option to true for a column to be visible in the mobile view.

layout: table
columns:
  alt:
    label: Alt
    mobile: true
Type

So far we offer three different column types, you can use to improve the preview of your data.

type description
text This is the standard column type
url If the value is a URL, you can convert the value to a link with this type
tags If the value is a comma-separated list of values or an array, you can use this type to show the value as tags.

File information

You can fine-tune the display text and additional information for every file in the list with the text and info options.

text

By default the filename is shown in the list for every file. You can use our template syntax with query language to fetch any information from the file and display that instead of the filename.

text: "{{ file.alt }}"

info

If you want to display additional information for each file, like a caption, category or any other field value, you can use the template syntax with query language in the info option.

info: "{{ file.dimensions }}"

Restricting uploads to certain file types

If you want to restrict what types of files can be uploaded to the field, assign a file blueprint with the blueprint option. In that file blueprint, set the accept option. See the docs about file blueprints.

By default, Kirby supports the following files types.

To upload file types not supported out of the box by Kirby, you can register new file types with the fileTypes extension in a plugin.

Batch delete files

When managing many files, it can be tedious to delete them one by one. Adding batch: true, allows you to select multiple files and delete them at once.

gallery:
  type: filelist
  batch: true

Preview images

The (preview) image for each item in the list is by default what is configured in the respective file blueprint. However, you can customize these further for your field with the same options as in the file blueprint:

type: filelist
image:
  back: pattern
  cover: true

Empty state

With the empty option you can define the message which is displayed when no files are listed in the field.

empty: No documents yet

Filtering files

parent

By default, the current page is being used as the parent to find files for the list. With this option, any page on your site can be the parent of the field.

parent: site.find("galleries")

query

The filelist field supports a query option to filter files using our query string syntax. Manual sorting will be disabled for fields with a query.

images:
  type: filelist
  label: Images
  query: page.images
  blueprint: image
documents:
  type: filelist
  label: Documents
  query: page.documents
  blueprint: document

If the query returns a site, page or user, the field lists the files of that model, e.g. query: page.parent.

Blueprint

You can define which blueprint each file in the list must have. This blueprint option will also be applied to any new file that gets uploaded. File blueprints can be set up in /site/blueprints/files.

blueprint: cover

In Kirby 5, this option was called template. The old name still works.

In combination with the query property, use the uploads option to set the file blueprint that will be assigned at upload.

Sorting

sortBy

You can sort the list of files by a given field in descending or ascending order.

sortBy: filename desc

You can pass PHP sorting type flags, for example to make sorting work with special language specific characters.

sortBy: filename SORT_LOCALE_STRING
sortBy: filename asc SORT_LOCALE_STRING

The sortBy option will automatically switch off manual sorting.

sortable

You can switch off manual sorting entirely with the sortable option.

sortable: false

flip

Use the flip option to enable/disable reverse sorting (default is false):

sortBy: filename
flip: true

Limits

limit

The limit property sets how many files will be shown per page. If there are more entries in the field, the pagination navigation will be shown at the bottom of the field.

limit: 20

max

You can define a maximum number of files, that will be allowed in this field. After the maximum is reached, the upload button will be hidden and no more files can be uploaded.

max: 10

min

You can also define the minimum number of files, that need to be added in order to make the parent page valid.

min: 2

Conditional display

Like any other field, a list can be shown or hidden based on the value of another field. Set the condition with the when option, using a field name as the key and the value it has to have.

In the following example, each field is shown based on a different value of the postType field:

fields:
  postType:
    type: select
    options:
      - Gallery
      - Image
      - Text
  gallery:
    type: filelist
    template: gallery-image
    layout: cards
    size: tiny
    when:
      postType: Gallery
  image:
    type: filelist
    template: single-image
    max: 1
    layout: cards
    when:
      postType: Image
  text:
    type: textarea
    when:
      postType: Text
  tags:
    type: tags
    when:
      postType: Text

See conditional fields for the full set of rules.

Search is disabled by default. You can use the search option to enable it.

fields:
  gallery:
    type: filelist
    search: true

Fetching files in the frontend

Through a field, you upload files to a page, either the current page or another parent page. Contrary to a filepicker field, the file does not become part of the content, i.e. it is not referenced in the content file.

If you assign a file blueprint to a particular field, you can filter by its name when fetching files in the frontend.

Assuming a filelist field like the following which uploads images to the current page and assigns a blueprint called gallery:

fields:
  gallery:
    type: filelist
    blueprint: gallery

You can then fetch those files in the frontend like this:

<?php $galleryImages = $page->images()->template('gallery'); ?>
<ul>
<?php foreach ($galleryImages as $image): ?>
    <li><img src="<?= $image->url() ?>" alt="<?= $image->alt() ?>"></li>
<?php endforeach ?>
</ul>