Drupal - Change The HTML Output of Field
So I have been working on migrating a giant website from Drupal 6 to Drupal 7. As I migrate the content into Drupal 7 and review it, I often refer back to the Drupal 6 node to make sure the content was migrated properly. I was getting annoyed with copying the Drupal 6 node id rendered on the Drupal 7 node's page, opening a new browser tab, bringing up the old domain and then appending /node/# to it. Instead, I wanted to change the way the field is rendered in Drupal 7 by providing a simple link back to the Drupal 6 page. This can be accomplished with the template_preprocess_field function.
Here is a basic example that will change the rendered output of a custom field:
/** * Implements template_preprocess_field(). */ function my_theme_preprocess_field(&$vars) { if ($vars['element']['#field_name'] == 'field_my_custom_field') { $vars['items'][0]['#markup'] = "I changed the output of my field!"; } }
After adding this code to the template.php file of your theme, replace "my_theme" with the machine name of your theme, then flush all of Drupal's caches. Use the Devel module's dpm function (e.g. dpm($vars['element']) to see what is inside your element.
Thanks to Art Williams for a nice example here: http://www.digett.com/blog/01/18/2012/change-output-single-field-drupal-7-node