Drupal 10: Programmatically Render A Node Using A Render Mode

$nid = 123;
$entityType = 'node';
$viewMode = 'default';

$storage = \Drupal::entityTypeManager()->getStorage($entityType);
$node = $storage->load($nid);
$viewBuilder = \Drupal::entityTypeManager()->getViewBuilder($entityType);
$build = $viewBuilder->view($node, $viewMode);


Add new comment

The content of this field is kept private and will not be shown publicly.
15 + 4 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.