Laravel 5.0 - Blade 模板错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25832749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.0 - Blade Template Errors
提问by Gravy
Just playing about with Laravel 5, and am having difficulties using the Blade templating syntax. It appears that all my special characters are being escaped. Have I something wrong with my setup?
只是在玩 Laravel 5,并且在使用 Blade 模板语法时遇到了困难。看来我所有的特殊字符都被转义了。我的设置有问题吗?
Just to show my setup, I have added the following to config/app.php
:
只是为了显示我的设置,我添加了以下内容config/app.php
:
Aliases: 'Form' => 'Illuminate\Html\FormFacade', 'Html' => 'Illuminate\Html\HtmlFacade'
Service Providers: 'Illuminate\Html\HtmlServiceProvider'
别名:'Form' => 'Illuminate\Html\FormFacade', 'Html' => 'Illuminate\Html\HtmlFacade'
服务提供商:'Illuminate\Html\HtmlServiceProvider'
Now here's my blade view:
现在这是我的刀片视图:
@extends('layout')
@section('content')
{{ Form::open() }}
{{ Form::close() }}
@stop
And here is the output in the browser:
这是浏览器中的输出:
<form method="POST" action="http://test.app:8000/categories/create" accept-charset="UTF-8"><input name="_token" type="hidden" value="m4RdpqdbbqQ2F7iwfDkSDKTzEmaBGNvpJbj5LnqE"> </form>
<form method="POST" action="http://test.app:8000/categories/create" accept-charset="UTF-8"><input name="_token" type="hidden" value="m4RdpqdbbqQ2F7iwfDkSDKTzEmaBGNvpJbj5LnqE"> </form>
And here is the output from view-source:
这是视图源的输出:
<!doctype HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My Site</title>
</head>
<body>
<header></header>
<content>
<form method="POST" action="http://test.app:8000/categories/create" accept-charset="UTF-8"><input name="_token" type="hidden" value="m4RdpqdbbqQ2F7iwfDkSDKTzEmaBGNvpJbj5LnqE">
</form>
</content>
</body>
</html>
回答by Marwelln
In Laravel 5, {{ }}
will auto escape. What you need to use now is {!! !!}
.
在Laravel 5 中,{{ }}
会自动转义。您现在需要使用的是{!! !!}
.
{!! Form::open() !!}
{!! Form::close() !!}
More read about the change can be seen on https://laracasts.com/discuss/channels/general-discussion/new-blade-tag-for-unescaped-data-thoughts(thanks to @user1960364).
有关更改的更多信息,请访问https://laracasts.com/discuss/channels/general-discussion/new-blade-tag-for-unescaped-data-thoughts(感谢@user1960364)。
回答by Bojan Lazarevic
If you mustuse the old (L4.2 or less) Blade syntax, add the following lines at the bottom of AppServiceProvider@register:
如果您必须使用旧的(L4.2 或更低版本)Blade 语法,请在 AppServiceProvider@register 底部添加以下行:
\Blade::setRawTags('{{', '}}');
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{{', '}}}');
This should not be done lightly, and may make your application more vulnerable to XSS exploits, so use it with caution.
这不应该掉以轻心,并且可能会使您的应用程序更容易受到 XSS 攻击,因此请谨慎使用。