Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Blade: escaping text and allowing new lines

Writer Olivia Zamora

I have a user-input text displayed on one of the pages. I want to allow new lines, though. How do I display the text, so it is escaped AND allows new lines?

I used nl2br() and Blade's tripple brackets {{{$text}}}, however, obviously, the tripple brackets escape <br/> tags as well.

Is there a way to combine escaping and HTML's new lines using Blade?

Thanks.

3 Answers

You can do the escaping first, using e() and then apply nl2br():

{{ nl2br(e($text)) }}

e() is the function Blade uses when compiling triple brackets

3

You can use this

{!! nl2br(e($text)) !!}
0

in simple approach you can use it in blade File

{!! nl2br(e($onlineSetting->instruction)) !!}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy