Controller 将数组传递给 Twig 模板。该数组包含正确 UTF-8 编码的字符串。我可以用 var_dump($theArray)
在 Controller 中检查这个.所有字符串都正确显示。
但在 Twig 上
{% for video in videos %}
{{ video.title_value | raw }} <br>
{% endfor %}
一些字符如
Ö,Ä,Ü
被这个取代 �
. Controller 和模板被编码 UTF-8 without BOM
和<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
设置。我必须做原始输出,因为字符串可能包含 html 标签。知道如何修复
�
?
最佳答案
我的工作解决方案是遵循 Twig 文档
http://twig.sensiolabs.org/doc/filters/convert_encoding.html
应用过滤器 {{ field|convert_encoding('UTF-8', 'iso-8859-1') }}
因为当你的子模板没有继承主模板时,经常会发生这种情况,在那里你定义了正确的元字符集
关于symfony - 原始内容的 Twig UTF-8 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10491522/