Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Laravel: Display HTML with Blade

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.
by

2 Answers

Bharatgxwzm
You need to use
{!! $text !!}

The string will auto escape when using {{ $text }}.
pankajshivnani123
Please use

{!! $test !!} 

Only in case of HTML while if you want to render data, sting etc. use

{{ $test }}

This is because when your blade file is compiled

{{ $test }} is converted to <?php echo e($test) ?> while

{!! $test !!} is converted to <?php echo $test ?>

Login / Signup to Answer the Question.