AL-zami
AL-zami

Reputation: 9066

what is the correct laravel syntax

while working with form in laravel blade this syntax works

{!!Form::token()!!} //with double exclamation mark

for including a remote js file this works

<script src="{{ asset('js/register.js')}}" ></script>

with no exclamation mark.In fact exclamation mark created problem .js file was not found error.

I want to know the difference of the two syntax .and when to use which one ?

Upvotes: 3

Views: 3337

Answers (1)

dev7
dev7

Reputation: 6369

From Laravel's documentation:

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

Note: Be very careful when echoing content that is supplied by users of your application. Always use the double curly brace syntax to escape any HTML entities in the content.

Using {{ $var }} will be equivalent to <?php echo htmlentities($var);?>

Using {!! $var !!}} is equivalent to <?php echo $var;?>

Generally speaking, you'd use {{ }} most of the time, unless there are special characters which are not showing since htmlentities is escaping them. Only in these cases you'd use {!! !!}}.

Hope this helps.

Upvotes: 15

Related Questions