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);

Comments

usmanjutt84 (not verified)

Fri, 06/26/2020 - 23:58

$view = \Drupal\views\Views::getView('blogs');
$view->setDisplay('blogs_embed_feed_all_rows');
$view->setOffset($offset);
$view->execute();
$view->render();

$result = ['#markup' => $view];
$renderer = \Drupal::service('renderer');
$html = $renderer->render($result);
print_r($html); exit;
OR
kint($html);exit;

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.