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.
Actually Laravel supports {{}} and {{{}}} to escape data.
By default you would use the following syntax {{ $some_variable }} to echo out the content of a specific variable in Blade. By default the {{ }} escapes the HTML tags. In the first case, you can see how the HTML elements were escaped, and in the second case where we use {!! !!} we got the actual HTML tags.
You can show HTML tags as plain text in HTML on a website or webpage by replacing < with < or &60; and > with > or &62; on each HTML tag that you want to be visible. Ordinarily, HTML tags are not visible to the reader on the browser.
In Laravel, @yield is principally used to define a section in a layout and is constantly used to get content from a child page unto a master page.
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 !!}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With