Twig: How to print special symbols, such as Copyri

2020-04-17 07:13发布

问题:

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:

™


标签: twig symbols