Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ImportTokenParser.php

class ImportTokenParser

Imports macros.

{% import 'forms.html' as forms %}

@internal

Hierarchy

  • class \Twig\TokenParser\AbstractTokenParser implements \Twig\TokenParser\TokenParserInterface
    • class \Twig\TokenParser\ImportTokenParser extends \Twig\TokenParser\AbstractTokenParser

Expanded class hierarchy of ImportTokenParser

1 file declares its use of ImportTokenParser
CoreExtension.php in vendor/twig/twig/src/Extension/CoreExtension.php

File

vendor/twig/twig/src/TokenParser/ImportTokenParser.php, line 27

Namespace

Twig\TokenParser
View source
final class ImportTokenParser extends AbstractTokenParser {
    public function parse(Token $token) : Node {
        $macro = $this->parser
            ->getExpressionParser()
            ->parseExpression();
        $this->parser
            ->getStream()
            ->expect(Token::NAME_TYPE, 'as');
        $name = $this->parser
            ->getStream()
            ->expect(Token::NAME_TYPE)
            ->getValue();
        $var = new AssignTemplateVariable(new TemplateVariable($name, $token->getLine()), $this->parser
            ->isMainScope());
        $this->parser
            ->getStream()
            ->expect(Token::BLOCK_END_TYPE);
        $this->parser
            ->addImportedSymbol('template', $name);
        return new ImportNode($macro, $var, $token->getLine());
    }
    public function getTag() : string {
        return 'import';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractTokenParser::$parser protected property
AbstractTokenParser::setParser public function Sets the parser associated with this token parser. Overrides TokenParserInterface::setParser
ImportTokenParser::getTag public function Gets the tag name associated with this token parser. Overrides TokenParserInterface::getTag
ImportTokenParser::parse public function Parses a token and returns a node. Overrides TokenParserInterface::parse
RSS feed
Powered by Drupal