ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_TokenParser_Use Class Reference

Imports blocks defined in another template into the current template. More...

+ Inheritance diagram for Twig_TokenParser_Use:
+ Collaboration diagram for Twig_TokenParser_Use:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 getTag ()
 Gets the tag name associated with this token parser. More...
 
- Public Member Functions inherited from Twig_TokenParser
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 getTag ()
 Gets the tag name associated with this token parser. More...
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

Imports blocks defined in another template into the current template.

{% extends "base.html" %}

{% use "blocks.html" %}

{% block title %}{% endblock %}
{% block content %}{% endblock %}
See also
http://www.twig-project.org/doc/templates.html#horizontal-reuse for details.

@final

Definition at line 28 of file Use.php.

Member Function Documentation

◆ getTag()

Twig_TokenParser_Use::getTag ( )

Gets the tag name associated with this token parser.

Returns
string The tag name

Implements Twig_TokenParserInterface.

Definition at line 64 of file Use.php.

65 {
66 return 'use';
67 }

◆ parse()

Twig_TokenParser_Use::parse ( Twig_Token  $token)

Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax

Implements Twig_TokenParserInterface.

Definition at line 30 of file Use.php.

31 {
32 $template = $this->parser->getExpressionParser()->parseExpression();
33 $stream = $this->parser->getStream();
34
36 throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
37 }
38
39 $targets = array();
40 if ($stream->nextIf('with')) {
41 do {
42 $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
43
44 $alias = $name;
45 if ($stream->nextIf('as')) {
46 $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
47 }
48
49 $targets[$name] = new Twig_Node_Expression_Constant($alias, -1);
50
51 if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
52 break;
53 }
54 } while (true);
55 }
56
58
59 $this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets))));
60
61 return new Twig_Node();
62 }
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:19
Represents a node in the AST.
Definition: Node.php:19
const BLOCK_END_TYPE
Definition: Token.php:30
const NAME_TYPE
Definition: Token.php:32
const PUNCTUATION_TYPE
Definition: Token.php:36
$template
if($format !==null) $name
Definition: metadata.php:146
$stream
PHP stream implementation.

References $name, GuzzleHttp\Psr7\$stream, $template, Twig_Token\BLOCK_END_TYPE, Twig_Token\NAME_TYPE, and Twig_Token\PUNCTUATION_TYPE.


The documentation for this class was generated from the following file: