views-view-table.tpl.php

  1. 3.x theme/views-view-table.tpl.php
  2. 2.x theme/views-view-table.tpl.php

Template to display a view as a table.

  • $title : The title of this group of rows. May be empty.
  • $header: An array of header labels keyed by field id.
  • $caption: The caption for this table. May be empty.
  • $header_classes: An array of header classes keyed by field id.
  • $fields: An array of CSS IDs to use for each field id.
  • $classes: A class or classes to apply to the table, based on settings.
  • $row_classes: An array of classes to apply to each row, indexed by row number. This matches the index in $rows.
  • $rows: An array of row items. Each row is an array of content. $rows are keyed by row number, fields within rows are keyed by field ID.
  • $field_classes: An array of classes to apply to each field, indexed by field id, then row number. This matches the index in $rows.

File

theme/views-view-table.tpl.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Template to display a view as a table.
  5. *
  6. * - $title : The title of this group of rows. May be empty.
  7. * - $header: An array of header labels keyed by field id.
  8. * - $caption: The caption for this table. May be empty.
  9. * - $header_classes: An array of header classes keyed by field id.
  10. * - $fields: An array of CSS IDs to use for each field id.
  11. * - $classes: A class or classes to apply to the table, based on settings.
  12. * - $row_classes: An array of classes to apply to each row, indexed by row
  13. * number. This matches the index in $rows.
  14. * - $rows: An array of row items. Each row is an array of content.
  15. * $rows are keyed by row number, fields within rows are keyed by field ID.
  16. * - $field_classes: An array of classes to apply to each field, indexed by
  17. * field id, then row number. This matches the index in $rows.
  18. * @ingroup views_templates
  19. */
  20. ?>
  21. <table <?php if ($classes) { print 'class="'. $classes . '" '; } ?><?php print $attributes; ?>>
  22. <?php if (!empty($title) || !empty($caption)) : ?>
  23. <caption><?php print $caption . $title; ?></caption>
  24. <?php endif; ?>
  25. <?php if (!empty($header)) : ?>
  26. <thead>
  27. <tr>
  28. <?php foreach ($header as $field => $label): ?>
  29. <th <?php if ($header_classes[$field]) { print 'class="'. $header_classes[$field] . '" '; } ?>>
  30. <?php print $label; ?>
  31. </th>
  32. <?php endforeach; ?>
  33. </tr>
  34. </thead>
  35. <?php endif; ?>
  36. <tbody>
  37. <?php foreach ($rows as $row_count => $row): ?>
  38. <tr <?php if ($row_classes[$row_count]) { print 'class="' . implode(' ', $row_classes[$row_count]) .'"'; } ?>>
  39. <?php foreach ($row as $field => $content): ?>
  40. <td <?php if ($field_classes[$field][$row_count]) { print 'class="'. $field_classes[$field][$row_count] . '" '; } ?><?php print drupal_attributes($field_attributes[$field][$row_count]); ?>>
  41. <?php print $content; ?>
  42. </td>
  43. <?php endforeach; ?>
  44. </tr>
  45. <?php endforeach; ?>
  46. </tbody>
  47. </table>

Related topics