Display CCK Fields In Your Page.tpl.php July 23, 2008

Drupal time!

If you want to use your CCK fields somewhere outside your node, you may find yourself wanting to put it somewhere in page.tpl.php. Now that it isn't at all hard to do - just a little different.

When we're using a CCK field in node.tpl.php or any of your node templates, we might do something like this:

[php]print $field_your_field[0]['view'];[/php]

Or whatever you may use, there are variations. Now, this doesn't quite work out as we want to in page.tpl.php. If we want to print a CCK field in page.tpl.php, we have to make use of the $node variable like this:

[php]print $node->field_your_field[0]['view'];[/php]

Simple, eh? Very logical too. It's just a little different, that's all. This works in Drupal 5.x, assuming of course that you're trying to print out the CCK field on the page containing the node to which it belongs. Otherwise you'd probably have to load the node manually.