You are here

views-view-table.html.twig in Drupal 10

Theme override 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: The table header columns.
    • attributes: Remaining HTML attributes for the element.
    • content: HTML classes to apply to each header cell, indexed by

    the header's key.

    • default_classes: A flag indicating whether default classes should be used.
  • caption_needed: Is the caption tag needed.
  • caption: The caption for this table.
  • accessibility_description: Extended description for the table details.
  • accessibility_summary: Summary for the table details.
  • rows: Table row items. Rows are keyed by row number.
    • attributes: HTML classes to apply to each row.
    • columns: Row column items. Columns are keyed by column number.
      • attributes: HTML classes to apply to each column.
      • content: The column content.
    • default_classes: A flag indicating whether default classes should be used.
  • responsive: A flag indicating whether table is responsive.
  • sticky: A flag indicating whether table header is sticky.
  • summary_element: A render array with table summary information (if any).

File

core/themes/bartik/templates/classy/views/views-view-table.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override 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: The table header columns.
  11. * - attributes: Remaining HTML attributes for the element.
  12. * - content: HTML classes to apply to each header cell, indexed by
  13. * the header's key.
  14. * - default_classes: A flag indicating whether default classes should be
  15. * used.
  16. * - caption_needed: Is the caption tag needed.
  17. * - caption: The caption for this table.
  18. * - accessibility_description: Extended description for the table details.
  19. * - accessibility_summary: Summary for the table details.
  20. * - rows: Table row items. Rows are keyed by row number.
  21. * - attributes: HTML classes to apply to each row.
  22. * - columns: Row column items. Columns are keyed by column number.
  23. * - attributes: HTML classes to apply to each column.
  24. * - content: The column content.
  25. * - default_classes: A flag indicating whether default classes should be
  26. * used.
  27. * - responsive: A flag indicating whether table is responsive.
  28. * - sticky: A flag indicating whether table header is sticky.
  29. * - summary_element: A render array with table summary information (if any).
  30. *
  31. * @see template_preprocess_views_view_table()
  32. */
  33. #}
  34. {%
  35. set classes = [
  36. 'views-table',
  37. 'views-view-table',
  38. 'cols-' ~ header|length,
  39. responsive ? 'responsive-enabled',
  40. sticky ? 'sticky-enabled',
  41. ]
  42. %}
  43. <table{{ attributes.addClass(classes) }}>
  44. {% if caption_needed %}
  45. <caption>
  46. {% if caption %}
  47. {{ caption }}
  48. {% else %}
  49. {{ title }}
  50. {% endif %}
  51. {% if (summary_element is not empty) %}
  52. {{ summary_element }}
  53. {% endif %}
  54. </caption>
  55. {% endif %}
  56. {% if header %}
  57. <thead>
  58. <tr>
  59. {% for key, column in header %}
  60. {% if column.default_classes %}
  61. {%
  62. set column_classes = [
  63. 'views-field',
  64. 'views-field-' ~ fields[key],
  65. ]
  66. %}
  67. {% endif %}
  68. <th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
  69. {%- if column.wrapper_element -%}
  70. <{{ column.wrapper_element }}>
  71. {%- if column.url -%}
  72. <a href="{{ column.url }}" title="{{ column.title }}" rel="nofollow">{{ column.content }}{{ column.sort_indicator }}</a>
  73. {%- else -%}
  74. {{ column.content }}{{ column.sort_indicator }}
  75. {%- endif -%}
  76. </{{ column.wrapper_element }}>
  77. {%- else -%}
  78. {%- if column.url -%}
  79. <a href="{{ column.url }}" title="{{ column.title }}" rel="nofollow">{{ column.content }}{{ column.sort_indicator }}</a>
  80. {%- else -%}
  81. {{- column.content }}{{ column.sort_indicator }}
  82. {%- endif -%}
  83. {%- endif -%}
  84. </th>
  85. {% endfor %}
  86. </tr>
  87. </thead>
  88. {% endif %}
  89. <tbody>
  90. {% for row in rows %}
  91. <tr{{ row.attributes }}>
  92. {% for key, column in row.columns %}
  93. {% if column.default_classes %}
  94. {%
  95. set column_classes = [
  96. 'views-field'
  97. ]
  98. %}
  99. {% for field in column.fields %}
  100. {% set column_classes = column_classes|merge(['views-field-' ~ field]) %}
  101. {% endfor %}
  102. {% endif %}
  103. <td{{ column.attributes.addClass(column_classes) }}>
  104. {%- if column.wrapper_element -%}
  105. <{{ column.wrapper_element }}>
  106. {% for content in column.content %}
  107. {{ content.separator }}{{ content.field_output }}
  108. {% endfor %}
  109. </{{ column.wrapper_element }}>
  110. {%- else -%}
  111. {% for content in column.content %}
  112. {{- content.separator }}{{ content.field_output -}}
  113. {% endfor %}
  114. {%- endif %}
  115. </td>
  116. {% endfor %}
  117. </tr>
  118. {% endfor %}
  119. </tbody>
  120. </table>