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).

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>
Copied!
<p class="bodytext">TYPO3 is a cool <strong>CMS</strong>
(<a href="https://www.typo3.org" target="_blank">TYPO3</a>).</p>
Copied!

The exact output depends on TYPO3 constants.

Arguments of the <f:format.html> ViewHelper 

current

current
Type
string
Initialize the content object with this value for current property.

currentValueKey

currentValueKey
Type
string
Define the value key, used to locate the current value for the content object

data

data
Type
mixed
Initialize the content object with this set of data. Either an array or object.

parseFuncTSPath

parseFuncTSPath
Type
string
Default
'lib.parseFunc_RTE'
Path to the TypoScript parseFunc setup.

table

table
Type
string
Default
''
The table name associated with the "data" argument.

parseFuncTSPath argument: formatting text with a custom parsing function 

The parseFuncTSPath argument specifies which TypoScript parseFunc configuration is used to process the content.

<f:format.html parseFuncTSPath="lib.parseFunc">
    {someText}
</f:format.html>
Copied!

or inline:

{someText -> f:format.html(parseFuncTSPath: 'lib.myParseFunc')}
Copied!

With a custom parsing function defined in TypoScript:

config/site/mysite/setup.typoscript
lib.myParseFunc < lib.parseFunc
lib.myParseFunc {
    // replace --- with soft-hyphen
    short.--- = &shy;
}
Copied!

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 dataWrap, you should pass structured data (Data transfer object (DTO) or named array) as data. This ensures that field references like {FIELD:title} are resolved correctly.

<f:format.html
    data="{someDto}"
    parseFuncTSPath="lib.myParseFunc"
>
    You entered the following in the form:
</f:format.html>
Copied!

You may get the following output:

You entered the following in the form:
<strong>TYPO3, greatest CMS ever</strong>
Copied!

With a custom parsing function defined in TypoScript:

config/site/mysite/setup.typoscript
lib.myParseFunc < lib.parseFunc
lib.myParseFunc {
    dataWrap = |<strong>{FIELD:title}</strong>
}
Copied!

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>
Copied!

You may get the following output:

Thanks Kasper for this great CMS
Copied!

With the following custom parsing function defined in TypoScript:

config/site/mysite/setup.typoscript
lib.myParseFunc < lib.parseFunc
lib.myParseFunc {
    setContentToCurrent = 1
}
Copied!

CurrentValueKey argument 

Use the currentValueKey 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>
Copied!

You may get the following output:

Content: How to install TYPO3 in under 2 minutes ;-)
Copied!

With the following custom parsing function defined in TypoScript:

config/site/mysite/setup.typoscript
lib.myParseFunc < lib.parseFunc
lib.myParseFunc {
    dataWrap = |{CURRENT:1}
}
Copied!