Blade doesn’t parse HTML inside double curly braces {{}}
In short: Use {!! $variable !!}
instead of {{ $variable }}
.
@php
$myText = '<b>Bold text</b>';
@endphp
{!! $myText !!}
Output: Bold text
More detailed Guide:
Problem:
Let’s say you have something like this coming from your database:
<p>Hello from HTML!</p>
As you can see, it’s text, but it has some HTML tags.
Laravel Blade will display it exactly as it is, but we probably don’t want that. In most cases, we expect our <p>
and other HTML tags to work rather than just being displayed.
Here is how it will be displayed with double curly braces: {{}}
:
{{$example}}
Output:
<p>Hello from HTML!</p>
Fix: Parsing HTML in Blade
Instead of that, we should use {!! $variable !!}
:
{!! $example !!}
Output:
Hello from HTML!
Full Example:
@php
$example = '<p>Hello from HTML!</p>';
@endphp
{!! $example !!}