1

I have a node template but instead of outputting $content, I want to have more control over what the template displays by printing each field individually.

Below are the fields I want to include:

$title field_img $body

What code would I replace with? Also, are there any significant disadvantages to using this method?

2
  • I think the Display Suite module would be your best bet.
    – Chapabu
    Nov 8, 2011 at 15:02
  • Thank you, Matt, I will have a look... I had actually started looking at it a few months ago but didn't have time to delve deeper.
    – Jane
    Nov 9, 2011 at 15:30

2 Answers 2

2

If you already have a custom node template (tpl file) to theme your node then you're halfway there. You can use <?php print_r($node); ?> to see the node structure and find out how to print your fields.

For example, to print those 3 fields, you can use something similar to:
<?php print $title; ?>
<?php print $node-field_img['view']; ?>
<?php print $node->content['body']['#value']; ?>

Remember to use the print_r($node) to check the structure and print the fields similarly as above while including the HTML for the layout.

0
1

First install and enable the devel module as it makes the process of looking at the $node object a lot easier.

Make sure you have a node.tpl.php in your theme (You can create your own node-my-content-type-name.tpl.php also but in D6 you need to have a node.tpl.php to make this work).

At the top of the node.tpl or your own tpl file add.

kpr($node);

you can then easily traverse the object/array. you can also use dpm($node). Remember if you exclude the $content variable any new fields that are added to your content type won't be output unless you specifically output them in your tpl. In D7 this has changed as you can use:

print render($content['field_example'])

and

print hide($content['field_example'])

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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