In Drupal 7 I frequently use node_view()
for rendering nodes (using view modes) in blocks or pages as follows:
$nids = array(123,456,789);
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
$node_view = node_view($node, 'teaser');
$output .= drupal_render($node_view);
}
$build['nodes']['#markup'] = $output;
return $build;
node_view()
/entity_view()
has been deprecated and replaced by a view builder as explained in change record Entities are now rendered by a view builder . The information is not detailed enough for me to be able to figure out how to achieve the same result.
How can you render nodes in Drupal 8 so that the output can be used in the render array of a block or page?