0

i have set up a view (drupal 7) with a field that rendered the full node (node referenced field), and i want to get rid off the extra classes and tags wrapped around the fields.

i have copied field.tpl to my templates dir, and no matter what i name it it doesn't effect anything. I have selected that in the field settings in views. and yes, cleared the cache always.

would i name it after the content type. or the view. i even left it at just field.tpl and still nothing.

2 Answers 2

1

If you want to override the views field template, the correct template file name would be views-view-fields.tpl.php.

You need to copy the template sites/all/modules/views/theme/views-view-field.tpl.php to your current enabled theme folder. Then update the file as you need.

Rescan template files in your view theming information. The file views-view-field.tpl.php should be highlighted with bold. You may need to fluch the cache. It is a view template to all the fields as a row.

enter image description here
If you want to theme a specific field, you could use views-view-field--[field_name].tpl.php. It is the most specific view template. You can check more in Views theming.

2
  • thank you, perfect! one thing, where is that panel you are showing above??
    – petergus
    Dec 21, 2012 at 8:56
  • 1
    @user10580, If you edit your view, you will see Advanced in the right most panel and then find Other > Theme: Information under it.
    – Sithu
    Dec 21, 2012 at 9:07
0

The easiest way to find out what the templates should be is to use hook_preprocess_field() in your themes template file.

/**
 * Implements template_preprocess_field().
 */
function THEME_preprocess_field(&$vars) {

  // Check for template suggestions
  var_dump($vars['theme_hook_suggestions']);

  // Add a less verbose field name class: .field-NAME
  $vars['classes_array'][] = drupal_html_class($vars['element']['#field_name']);

  // Use .field-body instead of .body
  if ($vars['element']['#field_name'] == 'body') {
    $vars['classes_array'][] = 'field-body';
  }

  // Remove some classes from the wrapper <div>.
  $classes_to_remove = array(
    'field',
    'field-label-' . drupal_html_class($vars['element']['#label_display']),
    'field-type-' . drupal_html_class($vars['element']['#field_type']),
    'field-name-' . drupal_html_class($vars['element']['#field_name']),
    'body',
    'clearfix',
  );
  $vars['classes_array'] = array_diff($vars['classes_array'], $classes_to_remove);
}

The following has the information you want...

$vars['theme_hook_suggestions']

See: http://drupal.org/node/1089656

Theres a few examples above to edit/remove classes. You can then remove any wrappers divs and extra markup from the template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.