我想在symfony2中更改默认的twig lexer。
class MyController
{
private $twig;
public function __construct( Environment $twig)
{
$this->twig = $twig;
$lexer = new Twig_Lexer($twig, array(
'tag_comment' => array('[#', '#]'),
'tag_block' => array('[%', '%]'),
'tag_variable' => array('[[', ']]'),
'interpolation' => array('#[', ']'),
));
$this->twig->setLexer($lexer);
}
public function indexAction()
{
return new Response($this->twig->render(
'@Template/index.html.twig'
));
}
}
对于angularjs,存在{{alert}}插值的变量,而来自symfony的响应是
Variable "alert" does not exist in @Template/index.html.twig at line 3
所以lexer不会改变