Twig: How to print special symbols, such as Copyright, Trademark, etc

廉价感情. 提交于 2019-12-20 03:51:00

问题


I want to use special symbols, but instead all I get printed question mark symbol �

I tried

{% autoescape 'html' %}
    {{ '©'|escape('html') }}   {# won't be double-escaped #}
    {{ '©'|escape(strategy) }} {# will be double-escaped #}
{% endautoescape %}

and it did not work.


回答1:


Use raw filter :

{{ '©'|raw }}

http://twig.sensiolabs.org/doc/filters/raw.html

If the output is supposed to be HTML, you can also use HTML entity notation, for example trademark sign:

{{ '™' }}

or email sign:

{{ '@' }}



回答2:


Since you want to display a static string and not a variable, you can write the character directly, you don't need to use the {{ }} tag:

©

Or by using the HTML entity cited by Miro:

™


来源:https://stackoverflow.com/questions/36880446/twig-how-to-print-special-symbols-such-as-copyright-trademark-etc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!