4 * This file is part of Twig.
6 * (c) 2011 Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * Imports blocks defined in another template into the current template.
16 * {% extends "base.html" %}
18 * {% use "blocks.html" %}
20 * {% block title %}{% endblock %}
21 * {% block content %}{% endblock %}
24 * @see http://www.twig-project.org/doc/templates.html#horizontal-reuse for details.
26 class Twig_TokenParser_Use
extends Twig_TokenParser
29 * Parses a token and returns a node.
31 * @param Twig_Token $token A Twig_Token instance
33 * @return Twig_NodeInterface A Twig_NodeInterface instance
35 public function parse(Twig_Token
$token)
37 $template = $this->parser
->getExpressionParser()->parseExpression();
38 $stream = $this->parser
->getStream();
40 if (!$template instanceof Twig_Node_Expression_Constant
) {
41 throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getFilename());
45 if ($stream->test('with')) {
49 $name = $stream->expect(Twig_Token
::NAME_TYPE
)->getValue();
52 if ($stream->test('as')) {
55 $alias = $stream->expect(Twig_Token
::NAME_TYPE
)->getValue();
58 $targets[$name] = new Twig_Node_Expression_Constant($alias, -1);
60 if (!$stream->test(Twig_Token
::PUNCTUATION_TYPE
, ',')) {
68 $stream->expect(Twig_Token
::BLOCK_END_TYPE
);
70 $this->parser
->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets))));
74 * Gets the tag name associated with this token parser.
76 * @return string The tag name
78 public function getTag()