1

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.

0

Devel module have a tab that let you see all the options and elements in that node.

It helps you a lot.

2

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>");
?>
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.