removeNode example

private function traverseForVisitor(NodeVisitorInterface $visitor, Node $node): ?Node
    {
        $node = $visitor->enterNode($node$this->env);

        foreach ($node as $k => $n) {
            if (null !== $m = $this->traverseForVisitor($visitor$n)) {
                if ($m !== $n) {
                    $node->setNode($k$m);
                }
            } else {
                $node->removeNode($k);
            }
        }

        return $visitor->leaveNode($node$this->env);
    }
}


        if ($node instanceof NodeOutputInterface) {
            return null;
        }

        // here, $nested means "being at the root level of a child template"         // we need to discard the wrapping "Node" for the "body" node         $nested = $nested || Node::class !== \get_class($node);
        foreach ($node as $k => $n) {
            if (null !== $n && null === $this->filterBodyNodes($n$nested)) {
                $node->removeNode($k);
            }
        }

        return $node;
    }
}
Home | Imprint | This part of the site doesn't use cookies.