ViewHelpers
Fluid ViewHelpers for rendering RTE image previews in backend templates.
Table of contents
RteImagePreviewViewHelper
- class RteImagePreviewViewHelper
-
- Fully qualified name
-
\Netresearch\
Rte CKEditor Image\ View Helpers\ Rte Image Preview View Helper
Renders a backend preview of RTE HTML content by stripping disallowed tags and truncating text while preserving HTML structure.
This ViewHelper replicates the preview logic from
Rtefor use in Content Blocks and other custom backend preview templates where the built-in renderer is not available.Image Preview Renderer New in version 13.6.0
Arguments
html
-
- Type
- string
- Required
true
The RTE HTML content to preview. Typically
{data.bodytext}in a Content Blocks backend preview template.
maxLength
-
- Type
- int
- Default
- 1500
Maximum number of text characters before truncation. When exceeded, the text is truncated with an ellipsis (
...). HTML tags do not count toward this limit.
allowedTags
-
- Type
- string
- Default
<img><p>
HTML tags to preserve in the preview output, in
strip_format. All other tags are stripped (their text content is kept).tags ()
Processing Pipeline
The ViewHelper processes HTML through three stages:
- Sanitization — Removes control characters (
\x00-\x1F), UTF-16 surrogates, and Unicode non-characters, replacing them with U+FFFD (replacement character). - Tag stripping — Calls
strip_with thetags () allowedTagsargument, keeping only<img>and<p>by default. - DOM-aware truncation — Parses the remaining HTML with
DOMDocument, walks the DOM tree counting text length, and truncates atmaxLengthwhile keeping all tags properly closed.
Usage with Content Blocks
Content Blocks is the official TYPO3-endorsed successor to Mask/DCE/Flux for
creating custom content element types. Content Blocks registers its own backend
preview templates (backend-preview.html), which do not use the
built-in
Rte.
To render RTE image previews in a Content Block, use this ViewHelper in the block's backend preview template:
<html xmlns:nr="http://typo3.org/ns/Netresearch/RteCKEditorImage/ViewHelpers"
data-namespace-typo3-fluid="true">
<nr:rteImagePreview html="{data.bodytext}" />
</html>
Custom Tag Allowlist
To also preserve <figure> and <figcaption> in the preview:
<nr:rteImagePreview html="{data.bodytext}"
allowedTags="<img><p><figure><figcaption>" />
Custom Truncation Length
To show a shorter preview (e.g., in a compact list view):
<nr:rteImagePreview html="{data.bodytext}" maxLength="300" />
Standard Content Elements
For standard tt_content types with RTE bodytext, you do not need this
ViewHelper. The built-in
Rte handles backend
previews automatically via TYPO3's PreviewRendererInterface.