protected function addGetTemplate(Twig_Compiler $compiler)
{
- if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) {
- $compiler
- ->write("\$this->env->loadTemplate(")
- ->subcompile($this->getNode('expr'))
- ->raw(")")
- ;
- } else {
- $compiler
- ->write("\$template = \$this->env->resolveTemplate(")
- ->subcompile($this->getNode('expr'))
- ->raw(");\n")
- ->write('$template')
- ;
- }
+ $method = $this->getNode('expr') instanceof Twig_Node_Expression_Constant ? 'loadTemplate' : 'resolveTemplate';
+ $compiler
+ ->write(sprintf('$this->env->%s(', $method))
+ ->subcompile($this->getNode('expr'))
+ ->raw(')')
+ ;
}
protected function addTemplateArguments(Twig_Compiler $compiler)
{
- if (false === $this->getAttribute('only')) {
- if (null === $this->getNode('variables')) {
- $compiler->raw('$context');
- } else {
- $compiler
- ->raw('array_merge($context, ')
- ->subcompile($this->getNode('variables'))
- ->raw(')')
- ;
- }
+ if (null === $this->getNode('variables')) {
+ $compiler->raw(false === $this->getAttribute('only') ? '$context' : 'array()');
+ } elseif (false === $this->getAttribute('only')) {
+ $compiler
+ ->raw('array_merge($context, ')
+ ->subcompile($this->getNode('variables'))
+ ->raw(')')
+ ;
} else {
- if (null === $this->getNode('variables')) {
- $compiler->raw('array()');
- } else {
- $compiler->subcompile($this->getNode('variables'));
- }
+ $compiler->subcompile($this->getNode('variables'));
}
}
}
$node = new Twig_Node_Include($expr, null, false, false, 1);
$tests[] = array($node, <<<EOF
// line 1
-\$template = \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
-\$template->display(\$context);
+\$this->env->resolveTemplate(((true) ? ("foo") : ("foo")))->display(\$context);
EOF
);