.. include:: /Includes.rst.txt .. _ConfigureCE-Preview: ==================================================== Configure Custom Backend Preview for Content Element ==================================================== To allow editors a smoother experience, all custom content elements and plugins should be configured with a corresponding backend preview that shows an approximation of the element's appearance in the TYPO3 page module. The following sections describe how to achieve that. .. note:: With TYPO3 10.3, the backend rendering process of content elements has been replaced by the new Fluid based `PreviewRenderer` if the feature toggle :guilabel:`Fluid based page module` is activated. The section below describes both the "classic" as well as the new way. With Fluid Based Page Module ============================ .. important:: The :php:`PreviewRenderer` usage is only active if the :guilabel:`fluid based page module` feature is enabled. This feature is activated by default in new installations of TYPO3 versions 10.3 and later. The feature toggle can be located in the :guilabel:`Settings` admin module under :guilabel:`Feature Toggles`. Or it can be set in PHP using :php:`$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['fluidBasedPageModule'] = true;`. A :php:`PreviewRenderer` is used to facilitate (record) previews in TYPO3. The class is responsible for generating the preview and the wrapping. Writing a PreviewRenderer ------------------------- A custom :php:`PreviewRenderer` must implement the interface :php:`\TYPO3\CMS\Backend\Preview\PreviewRendererInterface` which contains the following API methods: .. code-block:: php /** * Dedicated method for rendering preview header HTML for * the page module only. Receives $item which is an instance of * GridColumnItem which has a getter method to return the record. * * @param GridColumnItem * @return string */ public function renderPageModulePreviewHeader(GridColumnItem $item); /** * Dedicated method for rendering preview body HTML for * the page module only. * * @param GridColumnItem $item * @return string */ public function renderPageModulePreviewContent(GridColumnItem $item); /** * Render a footer for the record to display in page module below * the body of the item's preview. * * @param GridColumnItem $item * @return string */ public function renderPageModulePreviewFooter(GridColumnItem $item): string; /** * Dedicated method for wrapping a preview header and body HTML. * * @param string $previewHeader * @param string $previewContent * @param GridColumnItem $item * @return string */ public function wrapPageModulePreview($previewHeader, $previewContent, GridColumnItem $item); Implementing these methods allows you to control the exact composition of the preview. This means assuming your :php:`PreviewRenderer` returns :html:`
Body
` from the preview content rendering method and your wrapping method does :php:`return 'Body