You are here

public function Renderer::render in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::render()
  2. 9 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::render()

File

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

Class

Renderer
Turns a render array into an HTML string.

Namespace

Drupal\Core\Render

Code

public function render(&$elements, $is_root_call = FALSE) {

  // Since #pre_render, #post_render, #lazy_builder callbacks and theme
  // functions or templates may be used for generating a render array's
  // content, and we might be rendering the main content for the page, it is
  // possible that any of them throw an exception that will cause a different
  // page to be rendered (e.g. throwing
  // \Symfony\Component\HttpKernel\Exception\NotFoundHttpException will cause
  // the 404 page to be rendered). That page might also use
  // Renderer::renderRoot() but if exceptions aren't caught here, it will be
  // impossible to call Renderer::renderRoot() again.
  // Hence, catch all exceptions, reset the isRenderingRoot property and
  // re-throw exceptions.
  try {
    return $this
      ->doRender($elements, $is_root_call);
  } catch (\Exception $e) {

    // Mark the ::rootRender() call finished due to this exception & re-throw.
    $this->isRenderingRoot = FALSE;
    throw $e;
  }
}