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

Breadcrumb

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

class CaptureNode

Represents a node for which we need to capture the output.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Twig\Node\Node implements \Twig\Node\Countable, \Twig\Node\IteratorAggregate
    • class \Twig\Node\CaptureNode extends \Twig\Node\Node

Expanded class hierarchy of CaptureNode

File

vendor/twig/twig/src/Node/CaptureNode.php, line 22

Namespace

Twig\Node
View source
class CaptureNode extends Node {
    public function __construct(Node $body, int $lineno) {
        parent::__construct([
            'body' => $body,
        ], [
            'raw' => false,
        ], $lineno);
    }
    public function compile(Compiler $compiler) : void {
        $useYield = $compiler->getEnvironment()
            ->useYield();
        if (!$this->getAttribute('raw')) {
            $compiler->raw("('' === \$tmp = ");
        }
        $compiler->raw($useYield ? "implode('', iterator_to_array(" : '\\Twig\\Extension\\CoreExtension::captureOutput(')
            ->raw("(function () use (&\$context, \$macros, \$blocks) {\n")
            ->indent()
            ->subcompile($this->getNode('body'))
            ->write("yield from [];\n")
            ->outdent()
            ->write('})()');
        if ($useYield) {
            $compiler->raw(', false))');
        }
        else {
            $compiler->raw(')');
        }
        if (!$this->getAttribute('raw')) {
            $compiler->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset());");
        }
        else {
            $compiler->raw(';');
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
CaptureNode::compile public function Overrides Node::compile
CaptureNode::__construct public function Overrides Node::__construct
Node::$attributeNameDeprecations private property @var array&lt;string, NameDeprecation&gt;
Node::$attributes protected property
Node::$lineno protected property
Node::$nodeNameDeprecations private property @var array&lt;string, NameDeprecation&gt;
Node::$nodes protected property
Node::$sourceContext private property
Node::$tag protected property
Node::count public function
Node::deprecateAttribute public function
Node::deprecateNode public function
Node::getAttribute public function
Node::getIterator public function
Node::getNode public function
Node::getNodeTag public function
Node::getSourceContext public function
Node::getTemplateLine public function
Node::getTemplateName public function
Node::hasAttribute public function
Node::hasNode public function
Node::removeAttribute public function
Node::removeNode public function
Node::setAttribute public function
Node::setNode public function 1
Node::setNodeTag public function @internal
Node::setSourceContext public function
Node::__toString public function
RSS feed
Powered by Drupal