Reputation: 1146
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 ?
Upvotes: 8
Views: 5680
Reputation: 63
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
Upvotes: 0
Reputation: 81
"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)
Upvotes: 1