Finglish Finglish - 1 year ago 141
Twig Question

can you set is_safe for a global in a twig extension

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?

Answer Source

If your global is pure HTML that needs to be rendered like HTML you could mark it as safe by using

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

If the global is an object and returns the HTML you wrap your return value with a new Twig_Markup

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download