4 * This file is part of Twig.
6 * (c) 2009 Fabien Potencier
7 * (c) 2009 Armin Ronacher
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
14 * Represents an include node.
16 * @author Fabien Potencier <fabien@symfony.com>
18 class Twig_Node_Include
extends Twig_Node
implements Twig_NodeOutputInterface
20 public function __construct(Twig_Node_Expression
$expr, Twig_Node_Expression
$variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
22 parent
::__construct(array('expr' => $expr, 'variables' => $variables), array('only' => (Boolean
) $only, 'ignore_missing' => (Boolean
) $ignoreMissing), $lineno, $tag);
26 * Compiles the node to PHP.
28 * @param Twig_Compiler A Twig_Compiler instance
30 public function compile(Twig_Compiler
$compiler)
32 $compiler->addDebugInfo($this);
34 if ($this->getAttribute('ignore_missing')) {
41 $this->addGetTemplate($compiler);
43 $compiler->raw('->display(');
45 $this->addTemplateArguments($compiler);
47 $compiler->raw(");\n");
49 if ($this->getAttribute('ignore_missing')) {
52 ->write("} catch (Twig_Error_Loader \$e) {\n")
54 ->write("// ignore missing template\n")
61 protected function addGetTemplate(Twig_Compiler
$compiler)
63 if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant
) {
65 ->write("\$this->env->loadTemplate(")
66 ->subcompile($this->getNode('expr'))
71 ->write("\$template = \$this->env->resolveTemplate(")
72 ->subcompile($this->getNode('expr'))
79 protected function addTemplateArguments(Twig_Compiler $compiler)
81 if (false === $this->getAttribute('only
')) {
82 if (null === $this->getNode('variables
')) {
83 $compiler->raw('$context');
86 ->raw('array_merge($context, ')
87 ->subcompile($this->getNode('variables'))
92 if (null === $this->getNode('variables')) {
93 $compiler->raw('array()');
95 $compiler->subcompile($this->getNode('variables'));