Drupal print node from nid

10,422

Solution 1

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(###));

Solution 2

Since you want to use the "standard template for the node", what I suggest is that you load the node, and then use the node_view command.

I personally believe this is great practice and I use it constantly on all my websites. This keeps my themeing inside the default drupal node theme files (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's 2nd param is a boolean for using the teaser, which gives you even more control allowing you to use node-node_type-teaser.tpl.php)*

If you are looking to display the node contents for development purposes, there is no question that you should be using the "Devel" module which will allow you to use the following for any array, object, var etc:

dpm($node);

this function presents all of your node information and makes navigating it a breeze with the Krumo library which makes it possible to debug insane objects like $views (which are impossible through a print_r)

Solution 3

<?php print_r($node); ?>

Will print the entire node.

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

Share:
10,422
Will
Author by

Will

Updated on June 26, 2022

Comments