1

Twigs documentation for extensions show that it is possible to use "is_safe" with both simple_filters and and simple_functions, to prevent escaping of html tags in returned values, but I can see any examples of using is_safe with globals. Is there a way to do this?

4

1 回答 1

1

如果您的全局是需要像 HTML 一样呈现的纯 HTML,您可以使用以下方法将其标记为安全

$twig->addGlobal('my_html', new Twig_Markup($html, 'UTF-8'));

如果全局是一个对象并返回 HTML,则将返回值包装为新的Twig_Markup

于 2016-10-21T08:53:10.587 回答