什么是正确的laravel语法


what is the correct laravel syntax

在laravel blade中处理表单时,此语法适用于

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

对于包含远程js文件,这适用于

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

没有感叹号。事实上,感叹号创建的问题.js文件没有找到错误。

我想知道这两种语法的区别。什么时候用哪一种?

来自Laravel的文档:

默认情况下,Blade{{}}语句自动通过PHP的htmlentities函数可以防止XSS攻击。如果你不想如果要对您的数据进行转义,您可以使用以下语法:

你好,{!!$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.

使用{{ $var }}将等同于<?php echo htmlentities($var);?>

使用{!! $var !!}}相当于<?php echo $var;?>

一般来说,大多数时候都会使用{{ }},除非有特殊字符没有显示,因为htmlentities正在转义它们。只有在这种情况下,您才会使用{!! !!}}

希望这能有所帮助。