8

In order to convert my french html accents I try to change encoding by doing this in Twig :

{{ ddf.description | convert_encoding('UTF-8', 'HTML-ENTITIES') }}

But here is the message I get :

An exception has been thrown during the rendering of a template ("Notice: iconv(): Wrong charset, conversion from 'HTML-ENTITIES' to 'UTF-8' is not allowed").

Any idea ?

Gautier
  • 1,066
  • 1
  • 13
  • 24

2 Answers2

1

"HTML-ENTITIES" is not an encoding. It is a conversion function for special characters / accented encoding in (ISO ... UTF ...) to an equivalent in the same encoding or not depending on function and language.

Php htmlentities function: http://php.net/manual/en/function.htmlentities.php

Here is the html entities table: https://www.freeformatter.com/html-entities.html

Here is the list of encoding supported by iconv: how to get list of supported encodings by iconv library in php?

You can try using the "| raw" twig filter or create your own.

Unescape or html decode in Twig (PHP Templating)

K0rell
  • 71
  • 1
  • 9
0

Using automatic escaping should decode:

{% autoescape false %}
  {{ value|convert_encoding('UTF-8', 'HTML-ENTITIES') }}
{% endautoescape %}

If you don't use autoescape false, it will not decode the html entities. I used this for decoding ' to '.

Source: https://twig.symfony.com/doc/2.x/tags/autoescape.html

andreayaya
  • 63
  • 1
  • 8