views-view-table.html.twig

Default theme implementation for displaying a view as a table.

Available variables:

  • attributes: Remaining HTML attributes for the element.

    • class: HTML classes that can be used to style contextually through CSS.
  • title : The title of this group of rows.
  • header: Header labels.
  • header_classes: HTML classes to apply to each header cell, indexed by the header's key.
  • rows: Table row items. Rows are keyed by row number, fields within rows are keyed by field ID.

    • field: Table data field ID.
    • content: Table data content.
  • row_classes: HTML classes to apply to each row, indexed by row number. This matches the index in rows.
  • field_classes: HTML classes to apply to each row, indexed by row number. This matches the index in columns and rows.

See also

template_preprocess()

template_preprocess_views_view_table()

File

drupal/core/modules/views/templates/views-view-table.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for displaying a view as a table.
  5. *
  6. * Available variables:
  7. * - attributes: Remaining HTML attributes for the element.
  8. * - class: HTML classes that can be used to style contextually through CSS.
  9. * - title : The title of this group of rows.
  10. * - header: Header labels.
  11. * - header_classes: HTML classes to apply to each header cell, indexed by
  12. * the header's key.
  13. * - rows: Table row items. Rows are keyed by row number, fields within rows
  14. * are keyed by field ID.
  15. * - field: Table data field ID.
  16. * - content: Table data content.
  17. * - row_classes: HTML classes to apply to each row, indexed by row number.
  18. * This matches the index in rows.
  19. * - field_classes: HTML classes to apply to each row, indexed by row number.
  20. * This matches the index in columns and rows.
  21. *
  22. * @see template_preprocess()
  23. * @see template_preprocess_views_view_table()
  24. *
  25. * @ingroup themeable
  26. */
  27. #}
  28. <table{{ attributes }}>
  29. {% if title is not empty %}
  30. <caption>{{ title }}</caption>
  31. {% endif %}
  32. {% if header %}
  33. <thead>
  34. <tr>
  35. {% for key, field in header %}
  36. <th{{ header_classes[key] }} scope="col">
  37. {{ field }}
  38. </th>
  39. {% endfor %}
  40. </tr>
  41. </thead>
  42. {% endif %}
  43. <tbody>
  44. {% for row_count, row in rows %}
  45. <tr{{ row_classes[row_count] }}>
  46. {% for field, content in row %}
  47. <td{{ field_classes[field][row_count] }}>
  48. {{ content }}
  49. </td>
  50. {% endfor %}
  51. </tr>
  52. {% endfor %}
  53. </tbody>
  54. </table>

Related topics