Implements Twig_NodeVisitorInterface::leaveNode().
We use this to inject a call to render -> twig_render() before anything is printed.
twig_render
function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) {
if ($node instanceof \Twig_Node_Print) {
$this->isReference = FALSE;
$class = get_class($node);
return new $class(new \Twig_Node_Expression_Function('render', new \Twig_Node(array(
$node
->getNode('expr'),
)), $node
->getLine()), $node
->getLine());
}
if ($this->isReference) {
if ($node instanceof \Twig_Node_Expression_Name) {
$name = $node
->getAttribute('name');
return new TwigNodeExpressionNameReference($name, $node
->getLine());
}
elseif ($node instanceof \Twig_Function_Function) {
// Do something!
$this->isReference = FALSE;
}
}
return $node;
}