How do I print out the contents of the $node object in a node template in a way that is easily readable. I thought that <?php dpr($node);?>
would do it but that doesn't seem to work in my template.
3 Answers
Devel module have a tab that let you see all the options and elements in that node.
It helps you a lot.
Try below code
<?php
print "<pre>";
print_r($node);
print "</pre>";
?>
Alternatively you can use below code too...
<?php
drupal_set_message("<pre>" . print_r($node, 1) . "</pre>");
?>
To print specific fields in the template you can also try following code:
<?php print $node->field_name['und'][0]['value']; ?>
To get the value of the body field of node try following code:
<?php print $node->body['und'][0]['value']; ?>
For more clear understanding:
$node->field_name['und']
will be the Array of all the values of particular fields. So you can try and retrieve any field.
You can also use
<?php
print '<pre>;
var_dump($node);
print '</pre>';
?>
to see the detailed structure of node, as per suggestion of Anil Sagar.
-
1I read somewhere that accessing stuff via ['und'] is not recomended because it is a field related to localisation computerminds.co.uk/articles/… Commented Sep 13, 2012 at 12:27