Parent.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 Fabien Potencier
  6. * (c) 2009 Armin Ronacher
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. /**
  12. * Represents a parent node.
  13. *
  14. * @package twig
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class Twig_Node_Expression_Parent extends Twig_Node_Expression
  18. {
  19. public function __construct($name, $lineno, $tag = null)
  20. {
  21. parent::__construct(array(), array('output' => false, 'name' => $name), $lineno, $tag);
  22. }
  23. /**
  24. * Compiles the node to PHP.
  25. *
  26. * @param Twig_Compiler A Twig_Compiler instance
  27. */
  28. public function compile(Twig_Compiler $compiler)
  29. {
  30. if ($this->getAttribute('output')) {
  31. $compiler
  32. ->addDebugInfo($this)
  33. ->write("\$this->displayParentBlock(")
  34. ->string($this->getAttribute('name'))
  35. ->raw(", \$context, \$blocks);\n")
  36. ;
  37. } else {
  38. $compiler
  39. ->raw("\$this->renderParentBlock(")
  40. ->string($this->getAttribute('name'))
  41. ->raw(", \$context, \$blocks)")
  42. ;
  43. }
  44. }
  45. }