Twig_TokenParser_Use

Imports blocks defined in another template into the current template.

Defined (1)

The class is defined in the following location(s).

/vendor/twig/twig/lib/Twig/TokenParser/Use.php  
  1. class Twig_TokenParser_Use extends Twig_TokenParser 
  2. public function parse(Twig_Token $token) 
  3. $template = $this->parser->getExpressionParser()->parseExpression(); 
  4. $stream = $this->parser->getStream(); 
  5.  
  6. if (!$template instanceof Twig_Node_Expression_Constant) { 
  7. throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); 
  8.  
  9. $targets = array(); 
  10. if ($stream->nextIf('with')) { 
  11. do { 
  12. $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); 
  13.  
  14. $alias = $name; 
  15. if ($stream->nextIf('as')) { 
  16. $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); 
  17.  
  18. $targets[$name] = new Twig_Node_Expression_Constant($alias, -1); 
  19.  
  20. if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ', ')) { 
  21. break; 
  22. } while (true); 
  23.  
  24. $stream->expect(Twig_Token::BLOCK_END_TYPE); 
  25.  
  26. $this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets)))); 
  27.  
  28. public function getTag() 
  29. return 'use';