Custom autoescaper in Symfony 2
I need to add to Symfony 2 default autoescaper an ability to escape double curly brackets {{ and }}. So it should work without any modifications inside twig templates .
I've tried to add custom escaper as
$twig->getExtension('Twig_Extension_Core')->setEscaper('angular-html', $escaper);
and replace default escaping strategy "html" with custom "angular-html"
class AngularEscapingStrategy
{
public static function guess($name)
{
$strategy = Twig_FileExtensionEscapingStrategy::guess($name);
return ($strategy === 'html') ? 'angular-html' : $strategy;
}
}
So it works, but twig built-in functions like form_row or nl2br require escaper name to be equal 'html' to work properly:
new Twig_SimpleFilter('nl2br', 'nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))),
Is there any other way to extend default "html" escaper and keep its name?
链接地址: http://www.djcxy.com/p/81406.html上一篇: Symfony拆分了嵌入式表单
下一篇: 在Symfony 2中自定义自动换算器