Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 714
Dr.Neo Avatar asked Sep 24 '14 18:09

Dr.Neo


People also ask

How do you escape Laravel blade?

Actually Laravel supports {{}} and {{{}}} to escape data.

How do I show HTML code in blade?

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.

How do I display HTML tags as plain text in Laravel?

You can show HTML tags as plain text in HTML on a website or webpage by replacing < with &lt; or &60; and > with &gt; or &62; on each HTML tag that you want to be visible. Ordinarily, HTML tags are not visible to the reader on the browser.

What is @yield in Laravel?

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.


2 Answers

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.

like image 69
Ivan Topolcic Avatar answered Oct 14 '22 21:10

Ivan Topolcic


use this tag {!! description text !!}

like image 39
sanjay Avatar answered Oct 14 '22 20:10

sanjay