RenderTokenParser.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Symfony\Framework\TwigBundle\TokenParser;
  3. use Symfony\Framework\TwigBundle\Node\HelperNode;
  4. /*
  5. * This file is part of the Symfony package.
  6. *
  7. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  8. *
  9. * For the full copyright and license information, please view the LICENSE
  10. * file that was distributed with this source code.
  11. */
  12. /**
  13. * Wrapper for the actions helper render() method.
  14. *
  15. * {% render 'BlogBundle:Post:list' with ['path': ['limit': 2], 'standalone': false, 'alt': 'BlogBundle:Post:error'] %}
  16. *
  17. * @package Symfony
  18. * @subpackage Framework_TwigBundle
  19. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  20. */
  21. class RenderTokenParser extends \Twig_TokenParser
  22. {
  23. public function parse(\Twig_Token $token)
  24. {
  25. $nodes = array();
  26. $lineno = $token->getLine();
  27. $nodes[] = $this->parser->getExpressionParser()->parseExpression();
  28. if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
  29. $this->parser->getStream()->expect(\Twig_Token::NAME_TYPE, 'with');
  30. $nodes[] = $this->parser->getExpressionParser()->parseExpression();
  31. }
  32. $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
  33. return new HelperNode('actions', 'render', new \Twig_Node($nodes), true, $lineno, $this->getTag());
  34. }
  35. public function getTag()
  36. {
  37. return 'render';
  38. }
  39. }