Laravel 5.0 - Blade Template Errors

穿精又带淫゛_ 提交于 2019-11-28 00:21:24

问题


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?

Just to show my setup, I have added the following to config/app.php:

Aliases: 'Form' => 'Illuminate\Html\FormFacade', 'Html' => 'Illuminate\Html\HtmlFacade' Service Providers: '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>

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>
    &lt;form method=&quot;POST&quot; action=&quot;http://test.app:8000/categories/create&quot; accept-charset=&quot;UTF-8&quot;&gt;&lt;input name=&quot;_token&quot; type=&quot;hidden&quot; value=&quot;m4RdpqdbbqQ2F7iwfDkSDKTzEmaBGNvpJbj5LnqE&quot;&gt;

    &lt;/form&gt;

</content>

    </body>
</html>

回答1:


In Laravel 5, {{ }} will auto escape. What you need to use now is {!! !!}.

{!! 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).




回答2:


If you must use the old (L4.2 or less) Blade syntax, add the following lines at the bottom of 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.



来源:https://stackoverflow.com/questions/25832749/laravel-5-0-blade-template-errors

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