Skip to content

Instantly share code, notes, and snippets.

@woeldiche
Created November 28, 2012 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woeldiche/4160336 to your computer and use it in GitHub Desktop.
Save woeldiche/4160336 to your computer and use it in GitHub Desktop.
Add classes to fields in egedal theme
<?php
/**
* Implements template_preprocess_field().
*
* Adds classes to field based on field name.
*
* Good options are:
* - Field name: $vars['element']['#field_name'].
* - Content type: $vars['element']['#bundle'].
* - View mode: $vars['element']['#view_mode'].
*/
function egedal_preprocess_field(&$vars,$hook) {
// Uncomment next line to print field names.
// kpr($vars['element']['#field_name']);
// add class to a specific fields across content types.
switch ($vars['element']['#field_name']) {
case 'body':
$vars['classes_array'][] = 'text-content';
break;
case 'field_teaser':
// Add classes to field without removing old.
$vars['classes_array'][] = 'text-teaser';
break;
case 'field_image':
// Replace classes entirely, instead of adding extra.
$vars['classes_array'] = array('title-image');
break;
default:
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment