0

I have an article that has smart quotes in it, so I need to escape the article content. However, if I use

 article.body| e 

to escape the article, the html does not show up as formatted. And if I use

 article.body| raw 

the article is displayed correctly as html but the smart quotes are not escaped in the content.

Does anyone know how to escape content while correctly displaying the html?

1

2 Answers 2

1

You can specify a strategy for the escape filter.

'html' won't work for you here because it internally uses PHP's htmlspecialchars

'html' is the default strategy when using {{ var|e }}

You will need to create a custom escaping strategy for your use case.

... but if it's only the quotes which need to be replaced you could do a simple preg_replace on PrePersist and PreUpdate using Doctrine's Lifecyle Events.

Sign up to request clarification or add additional context in comments.

2 Comments

It still only shows up as unformatted html with all the tags and such as output :/
oh sorry guess i misread the question. you need to create a custom escaping strategy for your use case.
0

to show the special characters we can use like this {{ '<'|e }} it will print only angle angle bracket '<'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.