W3cubDocs

/Drupal 8

public function Renderer::renderPlaceholder

public Renderer::renderPlaceholder($placeholder, array $elements)

Renders final HTML for a placeholder.

Renders the placeholder in isolation.

Parameters

string $placeholder: An attached placeholder to render. (This must be a key of one of the values of $elements['#attached']['placeholders'].)

array $elements: The structured array describing the data to be rendered.

Return value

array The updated $elements.

Overrides RendererInterface::renderPlaceholder

See also

\Drupal\Core\Render\RendererInterface::render()

File

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

Class

Renderer
Turns a render array into a HTML string.

Namespace

Drupal\Core\Render

Code

public function renderPlaceholder($placeholder, array $elements) {
  // Get the render array for the given placeholder
  $placeholder_elements = $elements['#attached']['placeholders'][$placeholder];

  // Prevent the render array from being auto-placeholdered again.
  $placeholder_elements['#create_placeholder'] = FALSE;

  // Render the placeholder into markup.
  $markup = $this->renderPlain($placeholder_elements);

  // Replace the placeholder with its rendered markup, and merge its
  // bubbleable metadata with the main elements'.
  $elements['#markup'] = Markup::create(str_replace($placeholder, $markup, $elements['#markup']));
  $elements = $this->mergeBubbleableMetadata($elements, $placeholder_elements);

  // Remove the placeholder that we've just rendered.
  unset($elements['#attached']['placeholders'][$placeholder]);

  return $elements;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Renderer.php/function/Renderer::renderPlaceholder/8.1.x