Share icon

Are you looking for how to load node and node fields using nid to into your custom work, then this article is helps you to achieveing this.

Node is just entity in drupal and in drupal 8 entity is loading new way using function "entityTypeManager()"


Below is the example how to load the node using nid

$nid = 22; 
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$node = $node_storage->load($nid);

you can choose your nid "node_storage" load the $node object it is same "node_load()" function in drupal 7

So using this $node you can get the title and body and any custom fields you want

Get node's NID:


Get node's content type:


Other Fields like body and your custom fields:

$node->get('title')->value;  // title field
$node->get('created')->value;   // node created timestamp
$node->get('body')->value;   // "The full node body.

Images fields and fiile id


using same way we can get fields connected to that node.


Profile picture for user Jordan
Viktor (not verified)
Fri, 02/26/2021 - 15:34
This has been incredibly helpful, I've implemented it several times. All your tutorials have been quite helpful by the way, thank you so much!
Profile picture for user admin
Fri, 02/26/2021 - 15:38

Hi Viktor, thanks a lot for great words !

Add new comment

Restricted HTML