0

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 '15 at 22:49
  • It would not change, since there is a direct call to render(). – kiamlaluno Jun 12 '15 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. – kiamlaluno Jun 12 '15 at 4:03
0

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

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

Renders final HTML given a structured array tree.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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