# Files section

List, edit and upload files

****

- Read more: <https://getkirby.com/docs/guide/content/files>
- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/sections/files.php>

****

The files section 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 files section, 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

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=1416&amp;height=480&amp;enlarge=0"><img alt="" class="rounded" height="313" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=924&amp;height=313&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=462&amp;height=157&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=690&amp;height=234&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=924&amp;height=313&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=1380&amp;height=468&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=1416&amp;height=480&amp;enlarge=0 1848w" width="924"></a></figure>

## Example

```yaml "/site/blueprints/pages/project.yml"
title: Project

sections:
  gallery:
    label: Gallery
    type: files
    template: gallery
```
## Section shortcuts

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

```yaml
sections:

  files: true
```
This will add a `files` section with all default properties.

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

```yaml
sections:

  files:
    label: My Files
    template: cover
```
Keep in mind that the same section name can only be used once per blueprint.

## Section properties

The files section has multiple options to control what kind of files should be displayed, how they should be displayed and what happens if a new file is uploaded.



<div class="table">
	<table class="parameters">
		<thead>
			<tr>
				<th>Name</th>
				<th>Type</th>
				<th>Default</th>

								<th>Description</th>
							</tr>
		</thead>
		<tbody>
						<tr>
				<td>
					batch				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>false</code>
									</td>

								<td>Activates the batch delete option for the section</td>
							</tr>
						<tr>
				<td>
					columns				</td>
				<td><code class="type type-array">array</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Columns config for <code class="type">layout: table</code></td>
							</tr>
						<tr>
				<td>
					create				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>true</code>
									</td>

								<td>Option to switch off the upload button</td>
							</tr>
						<tr>
				<td>
					empty				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Sets the text for the empty state box</td>
							</tr>
						<tr>
				<td>
					flip				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>false</code>
									</td>

								<td>Enables/disables reverse sorting</td>
							</tr>
						<tr>
				<td>
					headline				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The headline for the section. This can be a simple string or a template with additional info from the parent page.</td>
							</tr>
						<tr>
				<td>
					help				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Sets the help text</td>
							</tr>
						<tr>
				<td>
					image				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Image options to control the source and look of preview</td>
							</tr>
						<tr>
				<td>
					info				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Optional info text setup. Info text is shown on the right (lists, cardlets) or below (cards) the title.</td>
							</tr>
						<tr>
				<td>
					label				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The label for the section. This can be a simple string or a template with additional info from the parent page. Replaces the <code class="type">headline</code> prop.</td>
							</tr>
						<tr>
				<td>
					layout				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'list'</code>
									</td>

								<td>Section layout. Available layout methods: <code class="type">list</code>, <code class="type">cardlets</code>, <code class="type">cards</code>, <code class="type">table</code>.</td>
							</tr>
						<tr>
				<td>
					limit				</td>
				<td><code class="type type-int">int</code></td>

				<td data-label="Default:">
															<code>20</code>
									</td>

								<td>Sets the number of items per page. If there are more items the pagination navigation will be shown at the bottom of the section.</td>
							</tr>
						<tr>
				<td>
					max				</td>
				<td><code class="type type-int">int</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Sets the maximum number of allowed entries in the section</td>
							</tr>
						<tr>
				<td>
					min				</td>
				<td><code class="type type-int">int</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Sets the minimum number of required entries in the section</td>
							</tr>
						<tr>
				<td>
					page				</td>
				<td><code class="type type-int">int</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Sets the default page for the pagination.</td>
							</tr>
						<tr>
				<td>
					parent				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Sets the query to a parent to find items for the list</td>
							</tr>
						<tr>
				<td>
					query				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Filters pages by a query. Sorting will be disabled</td>
							</tr>
						<tr>
				<td>
					rawvalues				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>false</code>
									</td>

								<td>Whether the raw content file values should be used for the table column previews. Should not be used unless it eases performance issues in your setup introduced with Kirby 4.2</td>
							</tr>
						<tr>
				<td>
					search				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>false</code>
									</td>

								<td>Enable/disable the search in the sections</td>
							</tr>
						<tr>
				<td>
					size				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'auto'</code>
									</td>

								<td>The size option controls the size of cards. By default cards are auto-sized and the cards grid will always fill the full width. With a size you can disable auto-sizing. Available sizes: <code class="type">tiny</code>, <code class="type">small</code>, <code class="type">medium</code>, <code class="type">large</code>, <code class="type">huge</code>, <code class="type">full</code></td>
							</tr>
						<tr>
				<td>
					sortBy				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Overwrites manual sorting and sorts by the given field and sorting direction (i.e. <code class="type">date desc</code>)</td>
							</tr>
						<tr>
				<td>
					sortable				</td>
				<td><code class="type type-bool">bool</code></td>

				<td data-label="Default:">
															<code>true</code>
									</td>

								<td>Enables/disables manual sorting</td>
							</tr>
						<tr>
				<td>
					template				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Filters all files by template and also sets the template, which will be used for all uploads</td>
							</tr>
						<tr>
				<td>
					text				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>'{{ file.filename }}'</code>
									</td>

								<td>Setup for the main text in the list or cards. By default this will display the filename.</td>
							</tr>
					</tbody>
	</table>
</div>

## Label

The label will be displayed above the files section. 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

```yaml
label: Gallery
```

### Multiple languages
```yaml
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 <a href="https://getkirby.com/docs/guide/blueprints/query-language">query language</a>.

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

<since v="5.2.0">
## Upload button

You can disable the upload button in a files section with the `create` option. This is useful for query-based sections where uploads wouldn't show up in the list.

```yaml
files:
  type: files
  query: page.files
  create: false
```
</since>

## 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.

```yaml
layout: list
```

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=1416&amp;height=480&amp;enlarge=0"><img alt="" class="rounded" height="313" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=924&amp;height=313&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=462&amp;height=157&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=690&amp;height=234&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=924&amp;height=313&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=1380&amp;height=468&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/cbdecb8202-1717846665/files-section.png?width=1416&amp;height=480&amp;enlarge=0 1848w" width="924"></a></figure>

### Cards layout

The `card` layout is great for all kinds of images.

```yaml
layout: cards
```

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/04fc7bec63-1717846665/files-section-cards.png?width=1776&amp;height=882&amp;enlarge=0"><img alt="" class="rounded" height="459" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/04fc7bec63-1717846665/files-section-cards.png?width=924&amp;height=459&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/04fc7bec63-1717846665/files-section-cards.png?width=462&amp;height=229&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/04fc7bec63-1717846665/files-section-cards.png?width=690&amp;height=343&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/04fc7bec63-1717846665/files-section-cards.png?width=924&amp;height=459&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/04fc7bec63-1717846665/files-section-cards.png?width=1380&amp;height=685&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/04fc7bec63-1717846665/files-section-cards.png?width=1776&amp;height=882&amp;enlarge=0 1848w" width="924"></a></figure>

<h3 id="__cardlets-layout"><a href="#__cardlets-layout" tabindex="-1">Cardlets layout</a></h3>
<p>The <code class="type">cardlets</code> layout is great for nice visual previews of files, while your text content is still representend decently.</p>
<figure class="code">
<pre><code class="language-yaml">layout: cardlets</code></pre>
</figure>

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/b87e82b33f-1717846665/files-section-cardlets.png?width=1776&amp;height=448&amp;enlarge=0"><img alt="" class="rounded" height="233" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/b87e82b33f-1717846665/files-section-cardlets.png?width=924&amp;height=233&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/b87e82b33f-1717846665/files-section-cardlets.png?width=462&amp;height=117&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/b87e82b33f-1717846665/files-section-cardlets.png?width=690&amp;height=174&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/b87e82b33f-1717846665/files-section-cardlets.png?width=924&amp;height=233&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/b87e82b33f-1717846665/files-section-cardlets.png?width=1380&amp;height=348&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/b87e82b33f-1717846665/files-section-cardlets.png?width=1776&amp;height=448&amp;enlarge=0 1848w" width="924"></a></figure>

### 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.

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/4030acb9fd-1717846665/files-section-table.png?width=1776&amp;height=548&amp;enlarge=0"><img alt="" class="rounded" height="285" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/4030acb9fd-1717846665/files-section-table.png?width=924&amp;height=285&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/4030acb9fd-1717846665/files-section-table.png?width=462&amp;height=143&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/4030acb9fd-1717846665/files-section-table.png?width=690&amp;height=213&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/4030acb9fd-1717846665/files-section-table.png?width=924&amp;height=285&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/4030acb9fd-1717846665/files-section-table.png?width=1380&amp;height=426&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/files/4030acb9fd-1717846665/files-section-table.png?width=1776&amp;height=548&amp;enlarge=0 1848w" width="924"></a></figure>

```yaml
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.

```yaml
layout: table
columns:
  alt: true
  dimensions: true
```

Each column can be customized with additional settings:

##### Label

```yaml
layout: table
columns:
  alt:
    label: Alt Text
```

##### Translated label

```yaml
layout: table
columns:
  alt:
    label:
      en: Alternative Text
      de: Alternativ Text
```

##### Alignment

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

```yaml
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:

```yaml
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.

```yaml
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.

```yaml
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.

```yaml
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 <a href="https://getkirby.com/docs/guide/blueprints/query-language">query language</a> to fetch any information from the file and display that instead of the filename.

```yaml
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 <a href="https://getkirby.com/docs/guide/blueprints/query-language">query language</a> in the `info` option.

```yaml
info: "{{ file.dimensions }}"
```
## Restricting uploads to certain file types

If you want to restrict what types of files can be uploaded to the given section, assign a file template using the `template` property. In your file template, set the `accept` option. See the docs about <a href="https://getkirby.com/docs/reference/panel/blueprints/file#accept">file blueprints</a>.

By default, Kirby supports <a href="https://getkirby.com/docs/guide/files/files#supported-file-types">the following files types</a>.

To upload file types not supported out of the box by Kirby, you can <a href="https://getkirby.com/docs/reference/plugins/extensions/file-types">register new file types with the `fileTypes` extension</a> in a plugin.

<since v="5.0.0">
## 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.

```yml
gallery:
  type: files
  batch: true
```
</since>

## Preview images

The (preview) image for each item in the list is by default what is <a href="https://getkirby.com/docs/reference/panel/blueprints/file#image-options">configured in the respective file blueprint</a>. However, you can customize these further for your section with the <a href="https://getkirby.com/docs/reference/panel/blueprints/file#image-options">same options</a> as in the file blueprint:

```yaml
type: files
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 section.

```yaml
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 section.

```yaml
parent: site.find("galleries")
```

### `query`

The files section supports a query option to filter files using our <a href="https://getkirby.com/docs/guide/blueprints/introduction#query-language">query string syntax</a>. Manual sorting will be disabled for sections with a query.

```yaml
images:
  type: files
  label: Images
  query: page.images
  template: image
documents:
  type: files
  label: Documents
  query: page.documents
  template: document
```

### Template

You can define which template each file in the list must have. This `template` option will also be applied to any new file that gets uploaded. Blueprints for file templates can be setup in `/site/blueprints/files`.

```yaml
template: cover
```

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.

```yaml
sortBy: filename desc
```

You can pass <a href="https://www.php.net/manual/en/function.sort.php">PHP sorting type flags</a>, for example to make sorting work with special language specific characters.

```yaml
sortBy: filename SORT_LOCALE_STRING
sortBy: filename asc SORT_LOCALE_STRING
```

<info>
The `sortBy` option will automatically switch off manual sorting.
</info>

### `sortable`

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

```yaml
sortable: false
```

### `flip`

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

```yaml
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 section, the pagination navigation will be shown at the bottom of the section.

```yaml
limit: 20
```

### `max`

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

```yaml
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.

```yaml
min: 2
```

<h2 id="conditional-sections"><a href="#conditional-sections" tabindex="-1">Conditional sections</a></h2>
<p>Like <a href="https://getkirby.com/docs/guide/blueprints/fields#conditional-fields">conditional fields</a>, sections can be shown/hidden based on the value of a given field (i.e. if a toggle is checked, a select field is at a certain option, etc.).</p>
<p>The condition for displaying the section is set with the <code class="type">when</code> option. In the <code class="type">when</code> option you define a field name as the key and the required value of that field. In the following example, the each section type is shown based on a different value of the <code class="type">postType</code> field:</p>
<figure class="code">
<pre><code class="language-yaml">sections:
  content:
    type: fields
    fields:
      postType:
        type: select
        options:
          - Gallery
          - Image
          - Text
  gallery:
    type: files
    template: gallery-image
    layout: cards
    size: tiny
    when:
      postType: Gallery
  image:
    type: files
    template: single-image
    max: 1
    layout: cards
    when:
      postType: Image
  text:
    type: fields
    fields:
      text:
        type: textarea
      tags:
        type: tags
    when:
      postType: Text</code></pre>
</figure>

## Search

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

```yaml
sections:
  gallery:
    type: files
    search: true
```

## Fetching files in the frontend

Through a section, you upload files to a page, either the current page or another parent page. Contrary to a files 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 template to a particular section, you can filter by this template when fetching files in the frontend.

Assuming a files section like the following which uploads images to the current page and assigns a template called `gallery`:

```yaml
sections:
  gallery:
    type: files
    template: gallery
```

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

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