Render.text ViewHelper <f:render.text>
New in version 14.2
This ViewHelper should be used whenever text fields from records are
displayed in HTML output. It can replace
{record. for
input fields, as well as
<f:
and
<f:
ViewHelper to render content based on records and fields from a TCA schema. Handles the processing of both simple and rich text fields.
Can also handle extbase models, you still need to provide the field name, not the property name.
Go to the source code of this ViewHelper: Render\TextViewHelper.php (GitHub).
The
<f: ViewHelper renders text-based fields from a record
according to their TCA configuration, automatically applying the correct formatting
(for example plain text, line breaks, or rich text).
It provides a unified way to render text fields and avoids manual formatting logic in templates.
Use this ViewHelper when rendering fields defined in TCA.
Do not use it for:
- Non-TCA properties
- Computed or virtual model properties
The ViewHelper is record-aware: it receives the full record and the field name, and renders the field based on its TCA configuration.
The record argument accepts:
RecordInterface PageInformation DomainObject Interface
This includes records, ContentBlockData objects, page information objects, and Extbase models.
Table of contents
Rendering texts with the record-transformation data processor
You can use the
<f: ViewHelper to render a TCA field, for
example of type Input.
<f:render.text record="{record} field="my_title" />
or
{f:render.text(record: record, field: 'my_title')}
or
{record -> f:render.text(field: 'my_title')}
tt_content.my_content_element {
# ...
dataProcessing {
10 = record-transformation
}
}
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns(
'tt_content',
[
'tx_mytheme_link_label' => [
'label' => 'my_theme.backend_fields:tt_content.tx_mytheme_link_label',
'config' => [
'type' => 'input',
'size' => 30,
'max' => 255,
],
],
],
);
ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'tx_mytheme_link_label',
'my_content_element',
'after:bodytext',
);
Rendering multi-line texts, including rich text
The
<f: ViewHelper can also be used instead of the
Format.html ViewHelper <f:format.html>
or Format.nl2br ViewHelper <f:format.nl2br>
to render text textarea fields (See TCA: Text areas)
It automatically determines the correct rendering method based on the field's TCA configuration.
<f:render.text record="{record}" field="tx_mytheme_my_richtext" />
<f:render.text record="{record}" field="tx_mytheme_my_textarea" />
tt_content.my_content_element {
# ...
dataProcessing {
10 = record-transformation
}
}
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns(
'tt_content',
[
'tx_mytheme_my_richtext' => [
'label' => 'my_theme.backend_fields:tt_content.tx_mytheme_my_richtext',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
'tx_mytheme_my_textarea' => [
'label' => 'my_theme.backend_fields:tt_content.tx_mytheme_my_textarea',
'config' => [
'type' => 'text',
'cols' => 20,
'rows' => 2,
],
],
],
);
ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'tx_mytheme_my_richtext,tx_mytheme_my_textarea',
'my_content_element',
'after:bodytext',
);
Rendering texts from Extbase models
The ViewHelper can also be used to display an Extbase model.
The Extbase model is internally converted to a
Record where the rendering method is
determined by the TCA definition of the field.
Usage with an Extbase model (property name differs from database field name):
<!-- Use the field name from the TCA not from the model: -->
<f:render.text record="{myModel}" field="my_link_text" />
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns(
'tx_myextension_domain_model_mymodel',
[
'my_link_text' => [
'label' => 'my_extension.backend_fields:tx_myextension_domain_model_mymodel.my_link_text',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
],
);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_domain_model_mymodel',
'my_link_text',
'my_content_element',
'after:bodytext',
);
The
field argument always refers to the database/TCA column name of the
underlying record, even if your Extbase model maps that column to a differently
named property.
Note that Extbase models need to contain all columns that should be rendered
and the record type column (if configured in TCA) for this to work correctly.
For example, an Extbase model that represents tt_ must map both bodytext
and ctype to be able to use
<f:.
For model properties that are not directly mapped to database / TCA fields,
use ViewHelpers like
<f:
if formatting is required, or output them directly:
{record. if no formatting is needed.
Arguments of the <f:render.text> ViewHelper
field
-
- Type
- string
- Required
- 1
The database field that should be rendered (even if extbase model is used).
record
-
- Type
- TYPO3\CMS\Frontend\Page\PageInformation|TYPO3\CMS\Core\Domain\RecordInterface|TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
A Record API Object or extbase model