Symfony2/Twig: how to tell the custom twig tag to NOT escape the output
The third argument of Twig_Function_Method::__construct()
is an array of options for the function. One of these options is is_safe
which specifies whether function outputs "safe" HTML/JavaScript code:
public function getFunctions(){ return array( 'thumbnail' => new \Twig_Function_Method($this, 'thumbnail', array( 'is_safe' => array('html') )) );}
Crozin's answer is correct but because \Twig_Function_Method
is now deprecated you can use \Twig_SimpleFunction
as such:
return [ new \Twig_SimpleFunction('thumbnail', [$this, 'thumbnail'], [ 'is_safe' => ['html'] ]),];