Render a Render array to HTML code

Render a Render array to HTML code

How to get HTML from drupal 8 renderer array ?

How to convert Render array into HTML output code ?

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

 

Render outside of the Render context:

 

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

Other posts