file views-view-table.tpl.php

Template to display a view as a table.

Available variables:

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

Related topics