Wednesday, December 3, 2008

The $fields array in Drupal (CCK)

the $fields array is very important for accessing field content when doing custom theming. Unfortunately field names are not well documented, nor are they intuitive. For example, the field name for a node:link field is view_node. In order to track down names of my fields I usually use print_r ... the trick here is that you must look for 'stdClass Object', almost always the index giving these objects as values are the names of the fields used within the $fields array.

For example:
[field_image_fid] => stdClass Object ( [content] =>

can be accessed in your tpl.php by:
$fields['field_image_fid']->content
Post a Comment