Round Rock / Austin, Texas
Drupal Web Developer

How to Print CCK Fields in Custom node Templates (node--custom.tpl.php)

How to Print CCK Fields in Custom node Templates (node--custom.tpl.php)

If you have a custom node template such as node--news.tpl.php and want to print out values of the fields there are a few ways to do this, depeding on what all you want to be rendored.

The two I use most often are:

1) The simplest way, which gives you all the wrapper classes:

        <?php print render($content['my_custom_field']); ?>

2) The more custom way, which gives JUST the raw value, without any of the extra divs around it. 

        <?php print $node->my_custom_field['und'][0]['value']; ?>

You can also use this method if you want to grab another element of the field.  For instance, if the field you are printing is an image field and you only want the image path you can use:

         <img src="<?php print file_create_url($node->field_home_catering_sec_image['und'][0]['uri']); ?>" />

If you want to see what elements are available to you for a particular field, do this:

        <?php print_r($node->my_custom_field); ?>


Check to See if a Field Exists on a Node