Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig UTF-8 encoding of raw content

Tags:

twig

symfony

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 ?

like image 981
UpCat Avatar asked May 08 '12 01:05

UpCat


1 Answers

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

like image 106
user3236290 Avatar answered Sep 24 '22 13:09

user3236290