Laravel Escaping All HTML in Blade Template
I'm building a small CMS in Laravel and I tried to show the content (which is stored in the DB). It is showing the HTML tags instead of executing them. Its like there is an auto html_entity_decode for all printed data.
<?php
class CmsController extends BaseController
{
public function Content($name)
{
$data = Pages::where('CID', '=', Config::get('company.CID'))
->where('page_name', '=', $name)
->first();
return View::make('cms.page')->with('content', $data);
}
}
I tried to print the content using the curly brace.
{{ $content->page_desc }}
and triple curly brace.
{{{ $content->page_desc }}}
And they give the same result. I need to execute those HTML tags instead of escaping them.
Change your syntax from {{ }}
to {!! !!}
.
As The Alpha said in a comment above (not an answer so I thought I'd post), in Laravel 5, the {{ }}
(previously non-escaped output syntax) has changed to {!! !!}
. Replace {{ }}
with {!! !!}
and it should work.
use this tag {!! description text !!}
I had the same issue. Thanks for the answers above, I solved my issue. If there are people facing the same problem, here is two way to solve it:
- You can use
{!! $news->body !!}
- You can use traditional php openning (It is not recommended) like:
<?php echo $string ?>
I hope it helps.