I have a string returned to one of my views, like this:
$text = '<p><strong>Lorem</strong> ipsum dolor <img src="images/test.jpg"></p>'
I'm trying to display it with Blade:
{{$text}}
However, the output is a raw string instead of rendered HTML. How do I display HTML with Blade in Laravel?
PS. PHP echo()
displays the HTML correctly.
Display HTML In Laravel Blade Views By default you would use the following syntax {{ $some_variable }} to echo out the content of a specific variable in Blade. By default the {{ }} escapes the HTML tags. In the first case, you can see how the HTML elements were escaped, and in the second case where we use {!! !!}
You can display HTML tags In Laravel blade using using {!! $data !!} and @php echo html_entity_decode($data) @endphp. It helps you to display the HTML tags as tags not as text.
Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates.
You need to use
{!! $text !!}
The string will auto escape when using {{ $text }}
.
For laravel 5
{!!html_entity_decode($text)!!}
Figured out through this link, see RachidLaasri answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With