Reputation: 29079
I have plain text containing URL markup like this:
$string = "This is a good \[example\]\(http://www.example.com\) for my problem."
Now I would like to pass this variable $string
to a Blade template and parse it like this:
This is a good <a href='http://www.example.com'>example</a> for my problem.
However, since {{ }}
uses htmspecialchars the output looks like that:
This is a good < ;a href='http://www.example.com'> ;example< ;/a> ; for my problem.
At the moment, I parse the string with a custom function in a controller to the wanted output and present it in a Blade template with {! $parsed_string !}
. Is there a way to change the default behavior of the function {{}}
in Laravel?
Upvotes: 1
Views: 266
Reputation: 75
If You do not want to escape any special character inside {{ }}, you can use
{!!....Your HTML code....!!}
Upvotes: 0
Reputation: 24276
Using {!! $yourVariable !!}
will let you output html elements.
From laravel docs:
Displaying Unescaped Data
By default, Blade
{{ }}
statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:
Hello, {!! $name !!}.
Upvotes: 4