field.tpl.php Default template implementation to display the value of a field.

This file is not used by core, which uses theme functions instead for performance reasons. The markup is the same, though, so if you want to use template files rather than functions to change field markup, copy this file to your custom theme. See theme_field() for a discussion of performance.

Copy this file and place it inside your theme. You'll likely want to rename the file so that it only affects the field you are trying to override. Possible file names for template suggestions include:

  • field.tpl.php
  • field--field-type.tpl.php
  • field--field-name.tpl.php
  • field--content-type.tpl.php
  • field--field-name--content-type.tpl.php

Available variables:

  • $items: An array of field values. Use render() to output them.
  • $label: The item label.
  • $label_hidden: Whether the label display is set to 'hidden'.
  • $classes: Array of classes that can be used to style contextually through CSS. The default values can be one or more of the following:

    • field: The current template type, i.e., "theme hook".
    • field-name-[field_name]: The current field name. For example, if the field name is "field_description" it would result in "field-name-field-description".
    • field-type-[field_type]: The current field type. For example, if the field type is "text" it would result in "field-type-text".
    • field-label-[label_display]: The current label position. For example, if the label position is "above" it would result in "field-label-above".

Other variables:

  • $element['#object']: The entity to which the field is attached.
  • $element['#view_mode']: Display mode, e.g. 'full' or 'teaser'.
  • $element['#field_name']: The field name.
  • $element['#field_type']: The field type.
  • $element['#field_language']: The field language.
  • $element['#field_translatable']: Whether the field is translatable or not.
  • $element['#label_display']: Position of label display, inline, above, or hidden.
  • $field_name_css: The css-compatible field name.
  • $field_type_css: The css-compatible field type.

See also





Related topics