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:


However, the output is a raw string instead of rendered HTML. How do I display HTML with Blade in Laravel 5?

PS. PHP echo() displays the HTML correctly.

9 Answers 11

up vote 293 down vote accepted

you need to do this way

{!! $text !!}

string will auto escape when you perform {{ }}

2 upvote
i think you should select this as answer. – apis17
1 upvote
Here are the Laravel docs that mention this: "If you do not want your data to be escaped, you may use the following syntax: Hello, {!! $name !!}." laravel.com/docs/5.5/blade#displaying-data – Ryan
i like it, visually really clear this is some different than usual stuff... !!! – Andrew

You can try this:

{!! $text !!}

You should have a look at: http://laravel.com/docs/5.0/upgrade#upgrade-5.0

For laravel 5


Figured out through this link, see RachidLaasri answer

1 upvote
Thanks..its working..{!! html_entity_decode($data) !!} – Priyabrata Atha
It's a true answer !!! thank you – Arash Hatami

Try this. It worked for me.

{{ html_entity_decode($text) }}

In Laravel Blade template, {{ }} wil escape html. If you want to display html from controller in view, decode html from string.

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 ?>

There is another way. If object purpose is to render html you can implement \Illuminate\Contracts\Support\Htmlable contract that has toHtml() method.

Then you can render that object from blade like this: {{ $someObject }} (note, no need for {!! !!} syntax).

Also if you want to return html property and you know it will be html, use \Illuminate\Support\HtmlString class like this:

public function getProductDescription()
    return new HtmlString($this->description);

and then use it like {{ $product->getProductDescription() }}.

Of course be responsible when directly rendering raw html on page.

If you want to escape the data use

{{ $html }}

If don't want to escape the data use

{!! $html !!}

But till Laravel-4 you can use

{{ HTML::link('/auth/logout', 'Sign Out', array('class' => 'btn btn-default btn-flat')) }}

When comes to Laravel-5

{!! HTML::link('/auth/logout', 'Sign Out', array('class' => 'btn btn-default btn-flat')) !!} 

You can also do this with the PHP function

{{ html_entity_decode($data) }}

go through the PHP document for the parameters of this function

html_entity_decode - php.net

In Php Laravel to display $test data in HTML page :-

{{ $test }}

In a different way

<? $test ?>


In the blade page,

Name: {{$data->name}}

Not the answer you're looking for? Browse other questions tagged or ask your own question.