We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

nl2br with escape html

Hello!

I have a "status" model, basically a body of text (varchar) attached to a user.

When I display it in Volt, I use the following:


{{ status.body|nl2br }}

However I want to escape html with |e so users cant post statuses linking to massive images that will take up the entire screen, When I use:


{{ status.body|nl2br|e }}

Images are not shown, but neither are new lines. Instead </ br> is shown.

How do I enable new lines, regular paragraphs, but disable html?

Bonus question: Is there any way of keeping a attached image within the < div >? Can't get it to worked for linked images.

Thank you!!

Change the filter order:

{{ status.body|e|nl2br }}

Regarding paragraphs and images, you will have to implement your own escaper