You are here

function theme_field in Content Construction Kit (CCK) 5

Format an individual field for display.

Parameters

$node: The node being displayed (provided for context).

$field: The field that is to be displayed (for information about the label, field type, and so forth).

$items: The actual items to theme. This will be a linear array, each element of which has a "view" property which contains the filtered, formatted contents of the item.

$teaser: Whether the node is being displayed as a teaser or full version.

$page: Whether the node is being displayed as a full web page.

Return value

An HTML string containing the fully themed field.

3 theme calls to theme_field()
content_panels_render_field in ./content_panels.inc
hook_field in ./field.php
Define the behavior of a field type.
_content_field_view in ./content.module
Format field output based on display settings.

File

./content.module, line 1043
Allows administrators to associate custom fields to content types.

Code

function theme_field(&$node, &$field, &$items, $teaser, $page) {
  $label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above';
  $label = check_plain(t($field['widget']['label']));
  $items_output = '';
  $count = 1;
  foreach ($items as $delta => $item) {
    if (!empty($item['view']) || $item['view'] === "0") {
      $items_output .= '<div class="field-item ' . ($count % 2 ? 'odd' : 'even') . '">';
      if ($label_display == 'inline') {
        $items_output .= '<div class="field-label-inline' . ($delta ? '' : '-first') . '">';
        $items_output .= $label . ':&nbsp;</div>';
      }
      $items_output .= $item['view'] . '</div>';
      $count++;
    }
  }
  $output = '';
  if (!empty($items_output)) {
    $output .= '<div class="field field-type-' . strtr($field['type'], '_', '-') . ' field-' . strtr($field['field_name'], '_', '-') . '">';
    if ($label_display == 'above') {
      $output .= '<div class="field-label">' . $label . ':&nbsp;</div>';
    }
    $output .= '<div class="field-items">' . $items_output . '</div>';
    $output .= '</div>';
  }
  return $output;
}