4 * This file is part of Twig.
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
14 * Represents a block call node.
16 * @author Fabien Potencier <fabien@symfony.com>
18 class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
21 * @param Twig_Node|null $template
23 public function __construct(Twig_NodeInterface $name, $template = null, $lineno, $tag = null)
25 if (is_bool($template)) {
26 @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
31 $nodes = array('name' => $name);
32 if (null !== $template) {
33 $nodes['template'] = $template;
36 parent::__construct($nodes, array('is_defined_test' => false, 'output' => false), $lineno, $tag);
39 public function compile(Twig_Compiler $compiler)
41 if ($this->getAttribute('is_defined_test')) {
42 $this->compileTemplateCall($compiler, 'hasBlock');
44 if ($this->getAttribute('output')) {
45 $compiler->addDebugInfo($this);
48 ->compileTemplateCall($compiler, 'displayBlock')
51 $this->compileTemplateCall($compiler, 'renderBlock');
56 private function compileTemplateCall(Twig_Compiler $compiler, $method)
58 if (!$this->hasNode('template')) {
59 $compiler->write('$this');
62 ->write('$this->loadTemplate(')
63 ->subcompile($this->getNode('template'))
65 ->repr($this->getTemplateName())
67 ->repr($this->getTemplateLine())
72 $compiler->raw(sprintf('->%s', $method));
73 $this->compileBlockArguments($compiler);
78 private function compileBlockArguments(Twig_Compiler $compiler)
82 ->subcompile($this->getNode('name'))
85 if (!$this->hasNode('template')) {
86 $compiler->raw(', $blocks');
89 return $compiler->raw(')');