Edit on GitHub
Jump to docs navigation

Twig Components / Methods / nl2br

nl2br(is_xhtml) is a Twig filter to insert HTML line breaks before all newlines in a string:

{{ "I like Twig.\nYou will like it too."|nl2br }}
{# outputs

    I like Twig.<br />
    You will like it too.



The nl2br filter pre-escapes the input before applying the transformation.

Source: Twig

Edit this page on GitHub
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.