function Renderer::renderRoot

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::renderRoot()
  2. 10 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::renderRoot()
  3. 11.x core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::renderRoot()

Overrides RendererInterface::renderRoot

File

core/lib/Drupal/Core/Render/Renderer.php, line 134

Class

Renderer
Turns a render array into a HTML string.

Namespace

Drupal\Core\Render

Code

public function renderRoot(&$elements) {
    // Disallow calling ::renderRoot() from within another ::renderRoot() call.
    if ($this->isRenderingRoot) {
        $this->isRenderingRoot = FALSE;
        throw new \LogicException('A stray renderRoot() invocation is causing bubbling of attached assets to break.');
    }
    // Render in its own render context.
    $this->isRenderingRoot = TRUE;
    $output = $this->executeInRenderContext(new RenderContext(), function () use (&$elements) {
        return $this->render($elements, TRUE);
    });
    $this->isRenderingRoot = FALSE;
    return $output;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.