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; ?>
Leave a reply