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?

Becksters
  • 33
  • 1
  • 12

2 Answers2

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.

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
0

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

Sandeep Gupta
  • 380
  • 4
  • 14