Laravel 6 escaping html Blade template

Asked

Viewed 93 times

3

I am displaying news registered in the database using Windows and Blade template, only that html is being escaped, I have tried several ways but I can not solve.

My controller returning query result to Blade:

 return view('public.news', [ 'data' => $news[0] ]); 

And in Florida I call it that:

{{ data.text }}

But html is being escaped, the browser does not interpret the tags, coming out that way:

<div><p>A Caixa Econômica Federal disponibilizou na terça-feira (7) o site e o aplicativo por meio do qual informais, autônomos, desempregados e MEIs já podem solicitar o auxílio emergencial de R$ 600.</p><p class="content-text__container "> <strong>

I’ve tried to use {! data.text !}, {!! data.text !!}, {{ html_entity_decode(data.text) }} ... and nothing, Blade neither interprets these actions, prints this way even in html, someone could help me solve?

2 answers

2

The flag autoescape (here) It’s the Twig template, not Blade. As much as Laravel lets you use both at the same time, it will confuse other developers later here.

I’m not sure which version of Laravel you’re using but the right two ways would be:

For Laravel 4 you can use:

{{ html_entity_decode($content) }}

To Laravel 5+ (here) you can use:

{!! $content !!}

2

I managed to solve using:

{% autoescape false %} {{ data.text }} {% endautoescape %}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.