Render node from Controller I have a controller that passes a list of nodes to a template for rendering. I think I'm missing something simple.

I've tried this with no success:

public function content() {
  $students = $this-&gt;getStudents();

  return [
    '#theme' =&gt; 'dashboard',
    '#students' =&gt; $students,
  ];
}

private function getStudents() {
  $user = $this-&gt;currentUser();

  $nids = \Drupal::entityQuery('node')
    -&gt;condition('type','student')
    -&gt;condition('uid', $user-&gt;id())
    -&gt;execute();
  $nodes = Node::loadMultiple($nids);
  return $nodes;
}


I have a dashboard theme function:

function dashboard_theme() {
  return [
    'dashboard' =&gt; [
    'variables' =&gt; ['students' =&gt; NULL],
    ],
  ];
}


And a twig template being called:

&lt;ul&gt;
  {% for student in students %}
  &lt;li&gt;{{ student }}&lt;/li&gt;
  {% endfor %}
&lt;/ul&gt;


This blows up the page with the error Object of type Drupal\node\Entity\Node cannot be printed, which is no surprise, I'm just not sure what/how to send a proper object to twig.
Of course as soon as I posted this I figured an answer. This looks a little ugly, but I guess this is the way to go:

public function content() {
  $nodes = $this-&gt;getStudents();

  foreach ($nodes as $node) {
    $student = \Drupal::entityTypeManager()
      -&gt;getViewBuilder('node')
      -&gt;view($node);
    $students[] = render($student);
  }

  return [
    '#theme' =&gt; 'dashboard',
    '#students' =&gt; $students,
  ];
}


Basically, I'm looping through the list of nodes, getting the view builder on each, then calling the render function and adding it to a new array. I had stumbled on this earlier because I was using viewMultiple, which output another array...

If you have a cleaner implementation with viewMultiple let me know.