src/Service/TemplateReplacer.php
public function getReplacedContents(TemplateContext $context)
    {
        $templateName = $context->getTemplateName();
        $source = $this->loader->getSource($templateName);

        $stream = $this->lexer->tokenize(
            $source,
            $templateName
        );

        $rootNode = $this->parser->parse($stream);
        $rootNode->setAttribute(NodeAttributes::ATTRIBUTE_SOURCE, $source);

        $this->setRootNode($rootNode, $rootNode);


        $replacements = new SplStack();
        $this->handleNode($rootNode, $replacements, $context);

        if (count($replacements) === 0) {
            return null;
        }

        return $this->handleReplacements($source, $replacements);
    }
public function getReplacedContents(TemplateContext $context)
    {
        $templateName = $context->getTemplateName();
        $source = $this->loader->getSource($templateName);

        $stream = $this->lexer->tokenize(
            $source,
            $templateName
        );

        $rootNode = $this->parser->parse($stream);
        $rootNode->setAttribute(NodeAttributes::ATTRIBUTE_SOURCE, $source);

        $this->setRootNode($rootNode, $rootNode);


        $replacements = new SplStack();
        $this->handleNode($rootNode, $replacements, $context);

        if (count($replacements) === 0) {
            return null;
        }

        return $this->handleReplacements($source, $replacements);
    }
@param TemplateContext $context

@return null|string string if any replacements were done
@throws \Twig_Error_Syntax