Sunday, August 28, 2011

Drupal 7 possible override field templates

field.tpl.php - Default template implementation to display the value of a field. This file is not used and is here as a starting point for customization only.

Possible override templates are:
  • 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
For example, if you want to override the 'field_image' in your 'product' content type, you should create the template field--field_image--product.tpl.php.

Futhermore, if you want to load the node in which field is attached, you should use the $element['#object'] entity.

For example, if you want to take the language of the node in which field is attached, you can use the following code <?php $node=$element['#object']; $lang = $node->language; ?>

No comments: