Add pagination to TYPO3 default File Links Content Element
Bonn, Germany, Fri, 20 Apr 2018 01:19:46 +0200
Ever wondered how to add a Fluid paginate widget to a non Extbase extension in TYPO3 #CMS? For example a core Content Element (CE) and fluid_styled_content? It is straight forward when you are familiar with TYPO3, but there was one not quite obvious workaround needed to make it complete. The following solution is tested in TYPO3 v9.1 and v9.2, but it is possible that there will be another solution in core in the future.
I have a TYPO3 default File Links [uploads] Content Element (CE) and wanted to output a collection from a folder with a lot of files. I was surprised, that there was no pagination available, but it is a fluid styled template, so it was easy to add a paginate widget.
Add a template override path to your Template constants:
Add to your ext Template setup following TypoScript to set an alternative template name for File Links CE. Also add a workaround for non-extbase elements like the File Links CE [uploads]. This is needed so that the Fluid paginate ViewHelper will also work. Otherwise you have pagination, but only results from the first page are shown, because no controller is executed.
You can take the default template from typo3/sysext/fluid_styled_content/Resources/Private/Templates/Uploads.html and save it at typo3conf/ext/myext/Resources/Private/ContentTemplates/MyFilePagination.html. In your customised template add the Fluid paginate widget ViewHelper around the for ViewHelper and change the variable according:
That's it.
I have a TYPO3 default File Links [uploads] Content Element (CE) and wanted to output a collection from a folder with a lot of files. I was surprised, that there was no pagination available, but it is a fluid styled template, so it was easy to add a paginate widget.
Add a template override path to your Template constants:
# Add Fluid Styled Content template override path
styles.templates.templateRootPath = EXT:myext/Resources/Private/ContentTemplates/
Add to your ext Template setup following TypoScript to set an alternative template name for File Links CE. Also add a workaround for non-extbase elements like the File Links CE [uploads]. This is needed so that the Fluid paginate ViewHelper will also work. Otherwise you have pagination, but only results from the first page are shown, because no controller is executed.
##
# Customised TYPO3's File Links Content Element with pagination template.
#
# CType: uploads
# Use a customised fluid styled content template
tt_content.uploads.templateName = MyFilePagination
# Workaround to add functionality for non-extbase elements (https://forge.typo3.org/issues/79430)
tt_content.uploads.extbase {
pluginName = filelist
controllerName = filelist
controllerExtensionName = myext
controllerActionName = show
}
You can take the default template from typo3/sysext/fluid_styled_content/Resources/Private/Templates/Uploads.html and save it at typo3conf/ext/myext/Resources/Private/ContentTemplates/MyFilePagination.html. In your customised template add the Fluid paginate widget ViewHelper around the for ViewHelper and change the variable according:
<f:widget.paginate objects="{files}" as="paginatedFiles" configuration="{itemsPerPage: 10, insertAbove: 1, insertBelow: 1, maximumNumberOfLinks: 10}">
<f:for each="{paginatedFiles}" as="file" iteration="fileIterator">
That's it.
This website is tracked using the Piwik analytics tool. If you do not want that your visits are logged this way you can set a cookie to prevent Piwik from tracking further visits of the site (opt-out).