HTML output of whole page I am trying to generate html output of whole page and then pass it to response array.I am doing something like this:

  $page = array(
  '#theme' =&gt; 'html',
  '#page_object' =&gt; new HtmlPage(render($content)),
   );


$content is a render array and new HtmlPage creates a HtmlPage object from an existing page. I am passing render($page) to the response object, but I am getting error this error:


  LogicException: A stray drupal_render() invocation with $is_root_call = TRUE is causing bubbling of attached assets to break. in Drupal\Core\Render\Renderer-&gt;doRender() (line 377 of core\lib\Drupal\Core\Render\Renderer.php).


What should I do to make this correct? Thanks
Try using renderer service instead as rendeer and drupal_render() is deprecated, e.g.

\Drupal::service('renderer')-&gt;renderRoot($content);



  Renders final HTML given a structured array tree.