Attention

TYPO3 v10 has reached end-of-life as of April 30th 2023 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.

Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v10 here: TYPO3 ELTS.

Working With Collections

The \TYPO3\CMS\Core\Resource\ResourceFactory class provides a convenience method to retrieve a File Collection.

$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$collection = $resourceFactory->getCollectionObject(1);
// Load the contents of the collection
$collection->loadContents();

In this example, we retrieve and load the content from the File Collection with a uid of "1". Any Collection implements the \Iterator interface, which means that a Collection can be looped over (once its content has been loaded). Thus if the above code passed the $collection variable to a Fluid view, you could do the following:

<ul>
        <f:for each="{collection}" as="file">
                <li>{file.title}</li>
        </f:for>
</ul>