PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.1.12
Responsive Menu – Create Mobile-Friendly Menu v3.1.12
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / vendor / twig / twig / lib / Twig / TokenParser / Block.php

Block.php in Responsive Menu – Create Mobile-Friendly Menu 3.1.12, at vendor/twig/twig/lib/Twig/TokenParser/Block.php

72 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 * (c) Armin Ronacher
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 /**
14 * Marks a section of a template as being reusable.
15 *
16 * <pre>
17 * {% block head %}
18 * <link rel="stylesheet" href="style.css" />
19 * <title>{% block title %}{% endblock %} - My Webpage</title>
20 * {% endblock %}
21 * </pre>
22 *
23 * @final
24 */
25 class Twig_TokenParser_Block extends Twig_TokenParser
26 {
27 public function parse(Twig_Token $token)
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 }
53 $stream->expect(Twig_Token::BLOCK_END_TYPE);
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 }
61
62 public function decideBlockEnd(Twig_Token $token)
63 {
64 return $token->test('endblock');
65 }
66
67 public function getTag()
68 {
69 return 'block';
70 }
71 }
72