A controller passes an array to a twig template. The array contains strings that correctly UTF-8 encoded. I can check this in the controller with var_dump($theArray)
. All strings are displayed correctly.
But in twig
{% for video in videos %}
{{ video.title_value | raw }} <br>
{% endfor %}
some characters like Ö,Ä,Ü
are replaced by this �
. The controller and the template are encoded UTF-8 without BOM
and
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
is set. I have to do the raw output because the strings may contain html tags. Any idea how to fix the �
?
the working solution for me was to follow the twig documentation http://twig.sensiolabs.org/doc/filters/convert_encoding.html
applying a filter {{ field|convert_encoding('UTF-8', ' iso-8859-1') }}
because this often happen when your sub- template is not inheriting the main one , where you had the correct meta charset defined
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With