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

Marks a section of a template as being reusable. More...

+ Inheritance diagram for Twig_TokenParser_Block:
+ Collaboration diagram for Twig_TokenParser_Block:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 decideBlockEnd (Twig_Token $token)
 
 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...
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

Marks a section of a template as being reusable.

 {% block head %}
   <link rel="stylesheet" href="style.css">
   <title>{% block title %}{% endblock %} - My Webpage</title>
 {% endblock %}

Definition at line 25 of file Block.php.

Member Function Documentation

◆ decideBlockEnd()

Twig_TokenParser_Block::decideBlockEnd ( Twig_Token  $token)

Definition at line 62 of file Block.php.

References Twig_Token\test().

63  {
64  return $token->test('endblock');
65  }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
+ Here is the call graph for this function:

◆ getTag()

Twig_TokenParser_Block::getTag ( )

Gets the tag name associated with this token parser.

Returns
string The tag name

Implements Twig_TokenParserInterface.

Definition at line 67 of file Block.php.

Referenced by parse().

68  {
69  return 'block';
70  }
+ Here is the caller graph for this function:

◆ parse()

Twig_TokenParser_Block::parse ( Twig_Token  $token)

Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax

Implements Twig_TokenParserInterface.

Definition at line 27 of file Block.php.

References $name, GuzzleHttp\Psr7\$stream, array, Twig_Token\BLOCK_END_TYPE, Twig_Token\getLine(), getTag(), Twig_Token\getValue(), and Twig_Token\NAME_TYPE.

28  {
29  $lineno = $token->getLine();
30  $stream = $this->parser->getStream();
31  $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
32  if ($this->parser->hasBlock($name)) {
33  throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext());
34  }
35  $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno));
36  $this->parser->pushLocalScope();
37  $this->parser->pushBlockStack($name);
38 
39  if ($stream->nextIf(Twig_Token::BLOCK_END_TYPE)) {
40  $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
41  if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
42  $value = $token->getValue();
43 
44  if ($value != $name) {
45  throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
46  }
47  }
48  } else {
49  $body = new Twig_Node(array(
50  new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
51  ));
52  }
54 
55  $block->setNode('body', $body);
56  $this->parser->popBlockStack();
57  $this->parser->popLocalScope();
58 
59  return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
60  }
Represents a node in the AST.
Definition: Node.php:18
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Represents a block node.
Definition: Block.php:18
Represents a block call node.
Represents a node that outputs an expression.
Definition: Print.php:18
if($format !==null) $name
Definition: metadata.php:146
getValue()
Definition: Token.php:103
Create styles array
The data for the language used.
getTag()
Gets the tag name associated with this token parser.
Definition: Block.php:67
getLine()
Definition: Token.php:87
const NAME_TYPE
Definition: Token.php:32
const BLOCK_END_TYPE
Definition: Token.php:30
+ Here is the call graph for this function:

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