我使用PHP表单生成器类和它的TinyMCE实现。然后我把它传递到一个小树枝模板。
如果我在TinyMCE中输入任何粗体文本,当它进入到Twig时,特殊字符将被转义。
:
<strong>im bold</strong>
显示在浏览器中,源代码是
<strong>im bold</strong>
我试过使用:
tinyMCE.init({
...
entity_encoding : "raw"
我还试着写了一个函数:
function html_chars($text) {
$badchars = array( "<" , "> ");
$goodchars = array("<" , ">" );
return str_replace($badchars, $goodchars, $text);
}
但这也不起作用。
有什么办法阻止这种替换吗?
使用Twig raw解决了这个问题:
{% autoescape true %}
{{ var|raw }} {# var won't be escaped #}
{% endautoescape %}