protected function optimizeRenderBlock($node, $env)
{
if ($node instanceof Twig_Node_Print && $node->getNode('expr') instanceof Twig_Node_Expression_BlockReference) {
- return new Twig_Node_BlockReference($node->getNode('expr')->getNode('name')->getAttribute('value'), $node->getLine(), $node->getNodeTag());
+ $name = $node->getNode('expr')->getNode('name');
+ if ($name instanceof Twig_Node_Expression_Constant) {
+ return new Twig_Node_BlockReference($name->getAttribute('value'), $node->getLine(), $node->getNodeTag());
+ } else {
+ return new Twig_Node_BlockReference($name, $node->getLine(), $node->getNodeTag());
+ }
}
return $node;
$this->assertInstanceOf('Twig_Node_BlockReference', $stream->getNode('body'));
}
+ public function testRenderVariableBlockOptimizer()
+ {
+ $env = new Twig_Environment(new Twig_Loader_String(), array('cache' => false, 'autoescape' => false));
+ $env->addExtension(new Twig_Extension_Optimizer());
+ $stream = $env->parse($env->tokenize('{{ block(name|lower) }}', 'index'));
+
+ $this->assertInstanceOf('Twig_Node_BlockReference', $stream->getNode('body'));
+ }
+
/**
* @dataProvider getTestsForForOptimizer
*/