Format.html ViewHelper <f:format.html>
Changed in version 14.0
The Render.text ViewHelper <f:render.text> should be used whenever text fields from records are displayed in HTML output.
Depending on the TCA definition of the rendered field nl2br is then
automatically applied for multi line text areas.
ViewHelper to render a string which can contain HTML markup by passing it to a TYPO3 parseFunc. This can sanitize unwanted HTML tags and attributes, and keep wanted HTML syntax and take care of link substitution and other parsing. Either specify a path to the TypoScript setting or set the parseFunc options directly. By default, lib.parseFunc_RTE is used to parse the string.
Note: The ViewHelper must not be used in backend context, as it triggers frontend logic. Instead, use <f:sanitize.html> within backend context to secure a given HTML string or <f:transform.html> to parse links in HTML.
Go to the source code of this ViewHelper: Format\HtmlViewHelper.php (GitHub).
Table of contents
Using the <f:format.html> ViewHelper with default arguments
<f:format.html>
{$myConstant.project} is a cool <b>CMS</b>
(<a href="https://www.typo3.org">TYPO3</a>).
</f:format.html>
<p class="bodytext">TYPO3 is a cool <strong>CMS</strong>
(<a href="https://www.typo3.org" target="_blank">TYPO3</a>).</p>
The exact output depends on TYPO3 constants.
Arguments of the <f:format.html> ViewHelper
current
-
- Type
- string
Initialize the content object with this value for current property.
currentValueKey
-
- Type
- string
Define the value key, used to locate the current value for the content object
data
-
- Type
- mixed
Initialize the content object with this set of data. Either an array or object.
parseFuncTSPath
-
- Type
- string
- Default
- 'lib.parseFunc_RTE'
Path to the TypoScript parseFunc setup.
table
-
- Type
- string
- Default
- ''
The table name associated with the "data" argument.
parseFuncTSPath argument: formatting text with a custom parsing function
The parse argument specifies which TypoScript parse
configuration is used to process the content.
<f:format.html parseFuncTSPath="lib.parseFunc">
{someText}
</f:format.html>
or inline:
{someText -> f:format.html(parseFuncTSPath: 'lib.myParseFunc')}
With a custom parsing function defined in TypoScript:
lib.myParseFunc < lib.parseFunc
lib.myParseFunc {
// replace --- with soft-hyphen
short.--- = ­
}
See also
For all options see the TypoScript reference, chapter parseFunc.
Data argument
Changed in version 14.0
The Render.text ViewHelper <f:render.text> should be used whenever text fields from records are displayed in HTML output.
Depending on the TCA definition of the rendered field nl2br is then
automatically applied for multi line text areas.
If you use TypoScript properties such as
field or
data,
you should pass structured data
(Data transfer object (DTO)
or named array) as data. This ensures that field references like
{FIELD: are resolved correctly.
<f:format.html
data="{someDto}"
parseFuncTSPath="lib.myParseFunc"
>
You entered the following in the form:
</f:format.html>
You may get the following output:
You entered the following in the form:
<strong>TYPO3, greatest CMS ever</strong>
With a custom parsing function defined in TypoScript:
lib.myParseFunc < lib.parseFunc
lib.myParseFunc {
dataWrap = |<strong>{FIELD:title}</strong>
}
Current argument
Use the current argument to override the current value used by the TypoScript
content object.
<f:format.html
current="{strContent}"
parseFuncTSPath="lib.myParseFunc"
>
I'm gone
</f:format.html>
You may get the following output:
Thanks Kasper for this great CMS
With the following custom parsing function defined in TypoScript:
lib.myParseFunc < lib.parseFunc
lib.myParseFunc {
setContentToCurrent = 1
}
CurrentValueKey argument
Use the current argument to define a value of data object as the
current value.
<f:format.html
data="{someDto}"
currentValueKey="header"
parseFuncTSPath="lib.content"
>
Content:
</f:format.html>
You may get the following output:
Content: How to install TYPO3 in under 2 minutes ;-)
With the following custom parsing function defined in TypoScript:
lib.myParseFunc < lib.parseFunc
lib.myParseFunc {
dataWrap = |{CURRENT:1}
}