0

I have this error in Drupal 8.9.20 in a custom module: "Error: Call to a member function __toString()" with this code:

$html = \Drupal::service('renderer')
->renderRoot($template)
->__toString();
$result = new Response($html, 200);

Until the update to Drupal 8.9, it worked.

With what should i replace "__toString()" ?

I tried to replace with getContent() but with no succes.

Bogdan
  • 1
  • You've cut off the end of the error message - it's saying you're calling a member function _on something other than an object_. So, look at what `->renderRoot()` can return - maybe you need to check it for errors. – IMSoP Mar 23 '22 at 11:34

0 Answers0