Extends.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. * Extends a template by another one.
  13. *
  14. * <pre>
  15. * {% extends "base.html" %}
  16. * </pre>
  17. */
  18. class Twig_TokenParser_Extends extends Twig_TokenParser
  19. {
  20. public function parse(Twig_Token $token)
  21. {
  22. if (!$this->parser->isMainScope()) {
  23. throw new Twig_Error_Syntax('Cannot extend from a block.', $token->getLine(), $this->parser->getFilename());
  24. }
  25. if (null !== $this->parser->getParent()) {
  26. throw new Twig_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $this->parser->getFilename());
  27. }
  28. $this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
  29. $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
  30. }
  31. public function getTag()
  32. {
  33. return 'extends';
  34. }
  35. }