1

I have a PHP variable in Laravel controller: $html= '<img src="/example.png">'

Then in view blade, I displayed it with {{$html}}.

But it isn't rendered as html element. It shows as a text/string like <img src="/example.png"> in browser.

2 Answers 2

3

You should use:

{!! $html !!}

Check this answer, it is also documented on the official documentation, on the section Displaying Unescaped Data

Sign up to request clarification or add additional context in comments.

1 Comment

Anyone reading this, just remember that unescaped means dangerous if any part of the string comes from user input.
0

Displaying Unescaped Data

By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:

Hello, {!! $name !!}.

Ref. https://laravel.com/docs/5.1/blade#displaying-data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.