Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 744
Kumaran Avatar asked Jan 27 '16 07:01

Kumaran


People also ask

What does {{ }} mean in Laravel?

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 !!}. Follow this answer to receive notifications.

What does :: mean in Laravel?

Basically its know as Scope resolution operator (::) Simply it is token which allow access to static, constant and overridden properties of method of a class. Example- in laravel we call model like this.

What is blade in Laravel?

Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates.

What are the two primary benefits of Laravel blade?

Two of the primary benefits of using Blade are template inheritance and sections. We can define a blade page as a combination of layout and sections. Since most of the general web applications will have the same layout across the web pages.


1 Answers

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

like image 177
Narendrasingh Sisodia Avatar answered Sep 21 '22 00:09

Narendrasingh Sisodia