Maybe this is a simple thing that I'm missing, but in my laravel blade template I have something like:
{{ Form::model(....) }}
... my fields ...
{{ Form::close() }}
This results with escaped HTML so the form tag is actually printed to the screen. However, if I do:
{!! Form::model(....) !!}
... my fields ...
{!! Form::close() !!}
it works as expected. Do I always need to use the {!! ... !!}
when outputting html? All the tutorials I've read up on just show using the normal convention of {{ Form::model(...) }}
to open the form. Thanks for any advice! Using Laravel 5 fwiw.
That is correct.
{{ ... }}
for raw html{{{ ... }}}
for escaping with htmlentities()
{!! ... !!}
for raw html{{{ ... }}}
for explicitly escaped content{{ ... }}
for the default behavior (which is escaped as well)
If you don't like it you can change all 3 of those tags with these methods:
Blade::setRawTags($openTag, $closeTag);
Blade::setContentTags($openTag, $closeTag);
Blade::setEscapedContentTags($openTag, $closeTag);
To restore the way how Laravel 4 handled things, you can do this:
Blade::setRawTags('{{', '}}');
Blade::setEscapedContentTags('{{{', '}}}');
It used to be that {{ text }}
was unescaped, and {{{ text }}}
was escaped, but that changed with Laravel 5. Now, it's {{ text }}
for escaped, and {!! text !!}
for unescaped. So yes, you'll always need the latter for HTML in Laravel 5.
Most likely, all of the tutorials you've read are using the older version. I'll be the first to admit that this can be a tad confusing. Haven't quite gotten used to it myself yet. :)
For reference: http://laravel.com/docs/5.0/templates - Laravel 5 http://laravel.com/docs/4.2/templates - Laravel 4
Laravel4.x: {{{ text }}}
:Content tags, @{{ text }}
: Raw tags, {{ text }}
: Escaped tags/Default.
Laravel5.x: {{ text }}
:Content tags, @{{ text }}
: Raw tags, {!! text !!}
: Escaped tags.
Blade is magic!