Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert_encoding not allowed in twig

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 ?

like image 541
Gautier Avatar asked Dec 20 '17 14:12

Gautier


1 Answers

"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)

like image 82
K0rell Avatar answered Oct 05 '22 06:10

K0rell