Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal print node from nid

I have a node id. In my code I want to output this node to the screen using the standard template for the node. How do I print the node to the screen?

like image 885
Will Avatar asked Nov 19 '10 02:11

Will


People also ask

How do I get current node in Drupal?

Consider the following: $node = \Drupal::routeMatch()->getParameter('node'); if ($node instanceof \Drupal\node\NodeInterface) { $nid = $node->id(); // Do whatever you need to do with the node ID here... }

How do I get a node ID?

How to find a node ID. To find the node ID of a particular node, go to the edit page for the node. The URL of the edit page for each node looks like demo.uiowa.edu/node/NID/edit, where NID is a number which is the node ID.

What is NID in Drupal?

Body node ID class module is used to add node ID (nid) and node type as a class to <body> tag on node pages. In Drupal 7 core there was a unique node ID class in the <body> tag. This is forward-port of that functionality for Drupal 8.


1 Answers

print_r() works fine if you want to just look at the object structure (and using the devel module, the dpm() function that passes that output through krumo is even better).

To view the rendered version of the node, you should call the Drupal API function that is used to take a node object and run all the processing and theming routines used to generate the node output. In that case, it is node_view():

node_view(node_load(###));
like image 162
Grayside Avatar answered Sep 17 '22 20:09

Grayside