Home / Snippets / How to Display HTML in Laravel Blade
How to Display HTML in Laravel Blade cover

How to Display HTML in Laravel Blade

2K

3 years ago

0 comments

Sometimes you might have a string of HTML tags/components that's returned from the database or 3rd party source and you want to render it in Laravel Blade. If using the normal blade "{{ $content }}" curly braces to output it, it will be rendered as a string and not HTML. This behavior happens because Laravel by default escapes the value when using the syntax.
{{ $content }}
To render the raw HTML you will have to unescape it and to do that you can make use of the following syntax.
{!! $renderHTMLContent !!}
By default using the syntax above automatically unescapes any value using the PHP "htmlspecialchars" function but make sure to validate the data if it's entered by the user. Behind the scene, the compiled template looks like below.
{{ $content }} is converted to <?php echo e($content); ?>
While for the unescaped version, it will be as follows.
{!! $renderHTMLContent !!} is converted to <?php echo $renderHTMLContent; ?>
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this