Format.nl2br ViewHelper <f:format.nl2br> 

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.

Wrapper for PHPs nl2br function. See https://www.php.net/manual/function.nl2br.php.

Go to the source code of this ViewHelper: Format\Nl2brViewHelper.php (GitHub).

Preserving line breaks in HTML output 

HTML ignores line breaks within text. To display text while preserving line breaks, you must convert newline characters such as \\n or \\r\\n into HTML line break elements <br />.

The <f:format.nl2br> ViewHelper uses PHP's nl2br() function to insert HTML line breaks.

User input
This is
a
string
Copied!
<f:format.nl2br>{userInput}</f:format.nl2br>
Copied!

or inline:

{userInput -> f:format.nl2br()}
Copied!
Output
This is<br />
a<br />
string
Copied!

Arguments of the <f:format.nl2br> ViewHelper 

value

value
Type
string
string to format