The Case of the Incognito Apostrophe

21 March, 2021
Cartoon apostrophe in sunglasses and spy hat

The site had been up for over two years. This should have been just another weekly hero piece. There was nothing exceptional about it. Select an image. Enter a heading and subheading into each respective plain text field.

Yet, there it was. What should have read:

The People's Choice

instead read:

The People's Choice

So, what it wasn't was an issue with the code, nor the character set, nor the filters. Since it was coming from a plain text field, it also was not an issue with CKEditor. 

Where was the problem? Twig. It seems that twig automatically does the encoding. There are a number of ways to overcome this, with the most frequent suggestion being:

{{ myfield|raw }}

However, raw output could be inviting disaster, depending on the source of the field data. The better way is this:

{% autoescape false %}
{{ myfield }}
{% endautoescape %}

 

Login or Register to Comment!