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' => 'html',
  '#page_object' => 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->doRender() (line 377 of core\lib\Drupal\Core\Render\Renderer.php).

What should I do to make this correct? Thanks

  • Try this: replace '#page_object' => render($content), with '#page' => render($content),
    – rpayanm
    Jun 11, 2015 at 22:49
  • It would not change, since there is a direct call to render().
    – apaderno
    Jun 12, 2015 at 1:41
  • Welcome to Drupal Answers. In order to give a more complete and useful answer, we need to see the complete code. The short answer is "never call render() or drupal_render()," but that is not much helpful.
    – apaderno
    Jun 12, 2015 at 4:03

1 Answer 1


Try using renderer service instead as rendeer and drupal_render() is deprecated, e.g.


Renders final HTML given a structured array tree.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.