0

We are using a variable like this, to render the text without special characters like HELP & SUPPORT,

{{ variable|render|striptags|trim|convert_encoding('UTF-8', 'HTML-ENTITIES') }}

After upgrading from Drupal 8 to 9, we are getting errors like,

Notice: iconv(): Wrong charset, conversion from HTML-ENTITIES' to UTF-8' is not allowed in twig_convert_encoding() (line 1009 of /var/www/html/stg.flowbusiness.co/vendor/twig/twig/src/Extension/CoreExtension.php)

And the variable is not displaying with convert_encoding function.

So, any suggestions to display the text without special characters in drupal 9.

DarkBee
  • 16,592
  • 6
  • 46
  • 58
selva
  • 11
  • 2
  • This may be a duplicate question. Please see this answer: https://stackoverflow.com/questions/47907964/convert-encoding-not-allowed-in-twig – Alex T. Jan 03 '22 at 15:54
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jan 15 '22 at 09:48

3 Answers3

1

Using |raw filter would normally render chars as you need.

This twig rendering tag

{{ variable|render|striptags|trim|convert_encoding('UTF-8', 'HTML-ENTITIES') }}

would become

{{ variable|raw }}

While & char is an HTML entity, it would be correctly render as raw, without showing special chars.

0

convert_encoding() in twig is function meant to convert a string from one encoding to another; HTML-ENTITIES is not an encoding; this why the error is raised. https://twig.symfony.com/doc/2.x/filters/convert_encoding.html

As it's not doing what you're using it for, you should remove that part.

If you want to have the html entities to be rendered correctly, you should remove the striptags part too.

jde
  • 198
  • 9
0

Note that if the variable is already encoded in UTF-8 and does not contain any HTML entities, then you can remove the convert_encoding() and html_entity_decode() filters altogether, like this: {{ variable|render|striptags|trim}}

Daniela
  • 454
  • 3
  • 9