I have the following code that renders a string into HTML output. How can I stop it from escaping the text for HTML?
$template = '{{ who }} bar';
$params = array('who' => "Foo's");
$twig = new \Twig_Environment(new \Twig_Loader_String);
var_dump($twig->render($template, $params));
Outputs:
string(14) "Foo's bar"
How can I make it output this instead?
string(14) "Foo's bar"
I understand that changing '{{ who }} bar'
to '{{ who|raw }} bar'
will fix the problem, but I want to solve this at the rendering stage. I do not want to change all of the templates.
I dug through the Twig code and found that this works fine:
$twig = new \Twig_Environment(new \Twig_Loader_String, array(
'autoescape' => false
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With