Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.0 - Blade Template Errors

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>
like image 753
Gravy Avatar asked Sep 14 '14 11:09

Gravy


2 Answers

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

like image 79
Marwelln Avatar answered Oct 14 '22 15:10

Marwelln


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.

like image 37
Bojan Lazarevic Avatar answered Oct 14 '22 13:10

Bojan Lazarevic