What is the difference between {{ }} and {!! !!} in laravel blade files?

喜夏-厌秋 提交于 2019-11-27 01:31:45
Narendrasingh Sisodia

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

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

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 !!}.

To escape data use

{{ $data }}

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

{!! $data !!}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!