Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping a string with Blade, rendering HTML

I have a $text variable that holds some text and HTML code. I would like to render its HTML, but still make sure the rest of the string is escaped.

$text = 'Example text with image <img src"image_1.jpg">. More text...'

// This will render the HTML but will NOT escape the string
{!! $text !!}

// This will escape and display the variable as raw string, with no HTML rendering
{{ $text }}

In Laravel 5, is there a way to escape a string with Blade while allowing HTML?

like image 348
lesssugar Avatar asked Nov 10 '22 15:11

lesssugar


1 Answers

I am not aware of such functionality in blade. You can not just allow specific HTML tags, because they may have unwanted stuff (like onload) inside them. Processing of string may be tricky. Have you considered markup language?

like image 108
Daniel Antos Avatar answered Nov 14 '22 22:11

Daniel Antos