---
title: "File collections"
manual: "TYPO3 Explained"
version: "13.4"
permalink: "https://docs.typo3.org/permalink/t3coreapi:collections-files@13.4"
source: "ApiOverview/Fal/Collections/Index.rst"
rendered: "2026-09-20T16:02:56+00:00"
---

# File collections {#collections-files}

File collections are collections of
[file references](https://docs.typo3.org/permalink/t3coreapi:fal-architecture-components-file-references@13.4).
They are used by the "File links" (download) content element.

![A file links content element](../../../Images/ManualScreenshots/Fal/FileDownloadWithCollection.png)

File collections are stored in the
[sys_file_collection](https://docs.typo3.org/permalink/t3coreapi:fal-architecture-database-sys-file-collection@13.4) table.
The selected files are stored in the
[sys_file_reference](https://docs.typo3.org/permalink/t3coreapi:fal-architecture-database-sys-file-reference@13.4) table.

Note that a file collection may also reference a folder, in which case
all files inside the folder will be returned when calling that collection.

![A folder collection](../../../Images/ManualScreenshots/Fal/FolderCollection.png)

## Collections API {#collections-api}

The TYPO3 Core provides an API to enable usage of collections
inside extensions. The most important classes are:

-   **`\TYPO3\CMS\Core\Resource\FileCollectionRepository`**

    Used to retrieve collections. It is not exactly an
    [Extbase repository](https://docs.typo3.org/permalink/t3coreapi:extbase-repository@13.4) but works in a similar way.
    The default "find" methods refer to the
    [sys_file_collection](https://docs.typo3.org/permalink/t3coreapi:fal-architecture-database-sys-file-collection@13.4)
    table and will fetch "static"-type collections.

-   **`\TYPO3\CMS\Core\Resource\Collection\StaticFileCollection`**

    This class models the static file collection. It is important to note
    that collections returned by the repository (described above) are "empty".
    If you need to access their records, you need to load them first, using
    method `loadContents()`. On top of some specific API methods,
    this class includes all setters and getters that you may need to access
    the collection's data. For accessing the selected files, just loop
    on the collection (see example).

-   **`\TYPO3\CMS\Core\Resource\Collection\FolderBasedFileCollection`**

    Similar to the `StaticFileCollection`, but for file collections based
    on a folder.

-   **`\TYPO3\CMS\Core\Resource\Collection\CategoryBasedFileCollection`**

    File collection based on a single [category](https://docs.typo3.org/permalink/t3coreapi:categories@13.4).

## Example {#collections-example}

The following example demonstrates the usage of collections. Here is what
happens in the controller:

**EXT:my_extension/Classes/Controller/MyController.php**

```php
<?php

declare(strict_types=1);

namespace Collections;

use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Resource\FileCollectionRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

final class MyController extends ActionController
{
  public function __construct(
    private readonly FileCollectionRepository $collectionRepository,
  ) {}

  /**
   * Renders the list of all existing collections and their content
   */
  public function listAction(): ResponseInterface
  {
    // Get all existing collections
    $collections = $this->collectionRepository->findAll() ?? [];

    // Load the records in each collection
    foreach ($collections as $aCollection) {
      $aCollection->loadContents();
    }

    // Assign the "loaded" collections to the view
    $this->view->assign('collections', $collections);

    return $this->htmlResponse();
  }
}

```

All collections are fetched and passed
to the view. The one specific step is the loop over all collections to load
their referenced records. Remember that a collection is otherwise "empty".

In the view we can then either use collection member variables as usual
(like their title) or put them directly in a loop to iterate over the
record selection:

**EXT:my_extension/Resources/Private/Templates/List.html**

```html
<f:section name="main">
  <ul class="collection with-header">
    <f:for each="{collections}" as="collection">
      <li class="collection-header">
        <h4>{collection.title} (Records from <code>{collection.itemTableName}</code>)</h4>
      </li>
      <f:for each="{collection}" as="record">
        <li class="collection-item">{record.name}</li>
      </f:for>
    </f:for>
  </ul>
</f:section>

```

Here is what the result may look like (the exact result will obviously
depend on the content of the selection):

![Collections plugin output](../../../Images/ManualScreenshots/Frontend/Fal/CollectionsOutput.png)
