Theming an individual file field

Last modified: April 1, 2009 - 13:15

Sometimes it is important to theme a specific filefield and not all file fields in general. However, filefield only provides formatter functions applying to all files. Therefore, you have to select in the formatter function the specific field you want to format. The following code shows how to do that for the default formatter. Note that for images and non generic files other formatter functions are used and must be overwritten.

<?php
function [theme_name]_filefield_formatter_default($element) {
 
$file = $element['#item'];
 
$field = content_fields($element['#field_name']);

  if (
$field['field_name'] == 'field_image') {
   
$output = 'Special output just for the field_image field';
  }

 
$output .= theme('filefield_item', $file, $field);
  return
$output;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.