Drupal theming lesson 5 Field theming. Field.tpl.php template
In this lesson, we continue theming Drupal, and this time we will theme fields. After this lesson, we will move on to theming Views output.
To theme a field, you need to copy the file modules/field/theme/field.tpl.php
into your theme's templates
folder and rename it according to one of the following patterns:
-
field--FIELD_TYPE.tpl.php — this template will apply to all fields of type
FIELD_TYPE
. For example, to theme all image fields, create a template namedfield--image.php
. -
field--FIELD_NAME.tpl.php — this template will apply to the field named
FIELD_NAME
. For example, to theme the field namedfield_images
, create a template namedfield--field_images.tpl.php
. -
field--BUNDLE.tpl.php — this template will apply to all fields added to an entity of type
BUNDLE
. For example, to theme all fields in a content type calledpage
, create a template namedfield--page.tpl.php
. -
field--FIELD_NAME--BUNDLE.tpl.php — this template will apply only to the field
FIELD_NAME
that belongs to an entity of typeBUNDLE
. For example, to theme thefield_images
field in a content type calledpage
, create a template namedfield--field_images--page.tpl.php
.
After copying and renaming the template, clear the cache and edit the new file. Descriptions of all available variables are included in the template’s comments.