Laravel 5.0 - Blade Template Errors

2020-02-11 03:30发布

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>

2条回答
啃猪蹄的小仙女
2楼-- · 2020-02-11 04:05

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

查看更多
beautiful°
3楼-- · 2020-02-11 04:08

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.

查看更多
登录 后发表回答