Render a Render array to HTML code. | Drupal 8

Render a Render array to HTML code.

Submitted by editor on Fri, 02/10/2017 - 21:16
Question

How to get HTML from drupal 8 renderer array ?
How to convert Render array into HTML output code ?

Example :

$result =  array(
  '#markup' => 'Hello. This is my First Page',
);
$renderer = \Drupal::service('renderer');
$html = $renderer->render($result);

 

Render outside of the Render context:

$renderer = \Drupal::service('renderer');
$html = $renderer->renderPlain($result);
#OR
$html = $renderer->renderRoot($result);

Add new comment