Blade string escaping, HTML rendering

I have a $text variable that contains some text and HTML code. I would like to display its HTML, but still make sure the rest of the line 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 }} 

Is there a way in Laravel 5 to escape a line with Blade by allowing HTML?

+5
source share
2 answers

I do not know about such functionality in the blade. You cannot just allow certain HTML tags because they can have unwanted things (like onload) inside them. String processing can be complicated. Did you read the markup language ?

+1
source

In this case, you need to perform manual string processing.

It is possible that the https://github.com/mewebstudio/Purifier cleaner will do what you need. This will make the lines harmless, and then you can safely print the html in it.

Otherwise, you need to write your own parser if nothing like this is found.

0
source

All Articles