function Renderer::renderRoot
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::renderRoot()
- 8.9.x core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::renderRoot()
- 10 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::renderRoot()
Renders final HTML given a structured array tree.
Calls ::render() in such a way that placeholders are replaced.
Should therefore only be used in occasions where the final rendering is happening, just before sending a Response:
- system internals that are responsible for rendering the final HTML
- render arrays for non-HTML responses, such as feeds
(Cannot be executed within another render context.)
Parameters
array $elements: The structured array describing the data to be rendered.
Return value
\Drupal\Component\Render\MarkupInterface The rendered HTML.
Overrides RendererInterface::renderRoot
File
-
core/
lib/ Drupal/ Core/ Render/ Renderer.php, line 99
Class
- Renderer
- Turns a render array into an HTML string.
Namespace
Drupal\Core\RenderCode
public function renderRoot(&$elements) {
if (!$elements) {
return '';
}
// 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;
try {
$output = $this->renderInIsolation($elements);
} finally {
$this->isRenderingRoot = FALSE;
}
if ((string) $output === '') {
return '';
}
return $elements['#markup'];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.