Escape text while allowing new lines in Laravel blade

I’ve run into an issue when I wanted to print out some text escaped, while also allowing new lines to be displayed in them.

In Laravel 5 the triple curly brackets {{{ ... }}} are used to output escaped character sequences. However when you need to output text, you cannot just put nlbr() around your content, because that way the line breaks will also get escaped.

To overcome this issue, just use the {!! ... !!} syntax that lets you output unescaped content and escape it manually using the e() function. Here is an example:

{!! nl2br(e($classifiedAd->description)) !!}
  • Fake Yankee

    Thanks. I needed just this.