Howto Drupal 7 Views 3 add class attribute to tables in views table format

Howto Drupal 7 Views 3 add class attribute to tables in views table format

Sometimes you wish to have a class to identify views tables. But currently views does not provide such a class attribute in the <table> element.

So there's an issue about that in https://drupal.org/node/1689472.

In #20 cybercampbell mentions a workaround solution until it is clear, if this will be solved in views too. I think it is worth mentioning it as a snippet:

  1. function THEME_preprocess_views_view_table(&$vars) {
  2.   $vars['classes_array'][] = 'table';
  3. }

and if you want striped tables:

  1. function THEME_preprocess_views_view_table(&$vars) {
  2.   $vars['classes_array'][] = 'table table-striped';
  3. }

That's still some more code to write, but until a fix it provides a lot of flexibility.
Did you try it out?

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.

Weitere Informationen über Formatierungsoptionen