I have been told it is a breeze to set up custom, structured content elements for the Backend in TYPO3 7.5, using the new fluid_styled_content system extension.
After looking at at sysext/fluid_styled_content
and sysext/backend
, I couldn't figure it out myself. Any hints?
Information source: fluid_styled_slider on Github
These information are also available here: https://usetypo3.com/custom-fsc-element.html
The official docs are online as well: https://docs.typo3.org/typo3cms/extensions/fluid_styled_content/latest/
PageTSconfig
To make our content element appear in the wizard for new content elements, we have to add it via PageTSconfig
TCA
Now we need to tell TYPO3 what fields to show in the backend. Therefore we have to extend the tt_content TCA configuration. This stuff is now done in the folder
Configuration/TCA/Override
. Let's add our new CType first (this could also be done inext_tables.php
):Now we determine what fields to show for our CType:
TypoScript
The new CType
fs_slider
needs a rendering definition. This is rather simple:The
lib.fluidContent
is not much more than the initialization of aFLUIDCONTENT
object. We just change the template name (make sure to at least add your template path tolib.fluidContent.templateRootPaths
) and specify which dataProcessors we are gonna use. Oh right, dataProcessors.DataProcessors
Those are PHP classes that get the data before it is passed to the fluidtemplate. They can manipulate the data or add stuff to be present in the template. The
TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
for instance resolves all attached media elements for us, so we can access the FileReference objects in the view.DanielGoerz\FluidStyledSlider\DataProcessing\FluidStyledSliderProcessor
is a custom processor to illustrate how this works.However, DataProcessors are optional.
The Fluid template
The last piece in the puzzle is the actual template that receives the data processed by all specified DataProcessors in the end. This is plain fluid as we know (and love) it:
Of course we can use Layouts and Partials here as well. Note how
{data}
contains the tt_content row from the rendered content element.{files}
is added by theTYPO3\CMS\Frontend\DataProcessing\FilesProcessor
and contains the attached media as proper objects.{slider.width}
is added by our own DataProcessor.Optional: Preview in Page Module
We probably want some kind of preview for our editors in the page module. There are two notable possibilities to achieve this:
Fluid template via PageTSconfigWe can simply specify a fluid template to be rendered as preview in PageTSconfig:
This template will receive all fields of the tt_content row directly. So
tt_content_drawItem Hook{header}
contains the header,{bodytext}
contains the bodytext and so on.If we want to do more sophisticated stuff like getting child records resolved, we can register to the
tt_content_drawItem
hook like this:Our class has to implement the
\TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
.Whatever we write into
$itemContent
will be rendered in the page module inside our content element.