3

In views when you use the table layout and don't select labels it still creates an empty header, for example:

<th class="views-field views-field-field-address-1"></th> 

I can hide it with CSS. What would I have to do to access the render array and unset the element before the HTML is generated?

Is there any other way to remove the <th> tag?

8

Implement hook_preprocess_views_view_table(&$vars) in theme or custom module and set $vars['header'] to empty array. Template completely ignores thead when header variable is empty. For example:

function MY_THEME_preprocess_views_view_table(&$vars) {
  if ($vars['view']->name == "my_view") {
    $vars['header'] = array();
  }
}
|improve this answer|||||
4

A more general solution to the problem could be implemented in your theme by preprocessing the theme_table.

In other words, in your template.php file of your theme, write a function like this:

function MY_THEME_preprocess_table(&$variables) {
  if (!empty($variables['header'])) {
    foreach($variables['header'] as $cell) {
      if (!empty($cell)) {
        return;
      }
    }
    $variables['header'] = array();
  }
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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