What is the difference between {{ }} and {!! !!} i

2020-01-26 08:29发布

In the laravel framework we can use blade to add PHP code in html file.
We are using both {{ }} and {!! !!} syntax in blade files of Laravel.
What is the difference between them?

5条回答
祖国的老花朵
2楼-- · 2020-01-26 08:41

If you don't want the data to be escaped then use {!! !!} else use {{ }}.

查看更多
甜甜的少女心
3楼-- · 2020-01-26 08:46

To escape data use

{{ $data }}

If you don't want the data to be escaped use below

{!! $data !!}
查看更多
4楼-- · 2020-01-26 08:48

Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

You can see more here:https://laravel.com/docs/master/blade

查看更多
Bombasti
5楼-- · 2020-01-26 08:49

from the documentation: https://laravel.com/docs/5.1/blade

By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:

Hello, {!! $name !!}.
查看更多
Ridiculous、
6楼-- · 2020-01-26 09:01

Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

If you pass data from your Controller to a View with some HTML styling like:

$first = "<b>Narendra Sisodia</b>";

And it is accessed, within Blade, with {{ $first }} then the output'll be:

<b>Narendra Sisodia</b>

But if it is accessed with {!! $first !!} then the output'll be:

Narendra Sisodia

查看更多
登录 后发表回答