Drupal print node by nid

I have a node identifier. In my code, I want to display this node on the screen using the standard template for node. How to print node on the screen?

+7
drupal drupal-6
source share
3 answers

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

To view the render version of a node, you must call the Drupal API function, which is used to accept the node object and run all the processing and processing procedures used to generate the node output. In this case, this is node_view () :

node_view(node_load(###)); 
+10
source share

Since you want to use the "standard template for node", I suggest you download node and then use node_view .

I personally think that this is a great practice, and I constantly use it on all my sites. This saves my theme inside drupal theme files by default node (node ​​-node_type.tpl.php)

Example:

 $nid = 123; $node = node_load($nid); $node_tpl_output = node_view($node); print $node_tpl_output; // the rendering of node-node_type.tpl.php 

* (note that node_view 2nd param is logical for using the teaser, which gives you even more control allowing you to use node -node_type-teaser.tpl.php) *

If you , you want to display the contents of node for development purposes, there is no doubt that you should use " Devel", which will allow you to use the following for any array, object, var, etc .:

 dpm($node); 

this function represents all of your node information and makes it navigate with the help of the Krumo library, which allows you to debug crazy objects such as $ views (which is not possible via print_r)

+4
source share
 <?php print_r($node); ?> 

Prints the entire node.

Check here for more details: http://drupal.org/node/11816

+1
source share

All Articles