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/stable/templates/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. 'cols-' ~ header|length,
  37. responsive ? 'responsive-enabled',
  38. sticky ? 'sticky-enabled',
  39. ]
  40. %}
  41. <table{{ attributes.addClass(classes) }}>
  42. {% if caption_needed %}
  43. <caption>
  44. {% if caption %}
  45. {{ caption }}
  46. {% else %}
  47. {{ title }}
  48. {% endif %}
  49. {% if (summary_element is not empty) %}
  50. {{ summary_element }}
  51. {% endif %}
  52. </caption>
  53. {% endif %}
  54. {% if header %}
  55. <thead>
  56. <tr>
  57. {% for key, column in header %}
  58. {% if column.default_classes %}
  59. {%
  60. set column_classes = [
  61. 'views-field',
  62. 'views-field-' ~ fields[key],
  63. ]
  64. %}
  65. {% endif %}
  66. <th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
  67. {%- if column.wrapper_element -%}
  68. <{{ column.wrapper_element }}>
  69. {%- if column.url -%}
  70. <a href="{{ column.url }}" title="{{ column.title }}" rel="nofollow">{{ column.content }}{{ column.sort_indicator }}</a>
  71. {%- else -%}
  72. {{ column.content }}{{ column.sort_indicator }}
  73. {%- endif -%}
  74. </{{ column.wrapper_element }}>
  75. {%- else -%}
  76. {%- if column.url -%}
  77. <a href="{{ column.url }}" title="{{ column.title }}" rel="nofollow">{{ column.content }}{{ column.sort_indicator }}</a>
  78. {%- else -%}
  79. {{- column.content }}{{ column.sort_indicator }}
  80. {%- endif -%}
  81. {%- endif -%}
  82. </th>
  83. {% endfor %}
  84. </tr>
  85. </thead>
  86. {% endif %}
  87. <tbody>
  88. {% for row in rows %}
  89. <tr{{ row.attributes }}>
  90. {% for key, column in row.columns %}
  91. {% if column.default_classes %}
  92. {%
  93. set column_classes = [
  94. 'views-field'
  95. ]
  96. %}
  97. {% for field in column.fields %}
  98. {% set column_classes = column_classes|merge(['views-field-' ~ field]) %}
  99. {% endfor %}
  100. {% endif %}
  101. <td{{ column.attributes.addClass(column_classes) }}>
  102. {%- if column.wrapper_element -%}
  103. <{{ column.wrapper_element }}>
  104. {% for content in column.content %}
  105. {{ content.separator }}{{ content.field_output }}
  106. {% endfor %}
  107. </{{ column.wrapper_element }}>
  108. {%- else -%}
  109. {% for content in column.content %}
  110. {{- content.separator }}{{ content.field_output -}}
  111. {% endfor %}
  112. {%- endif %}
  113. </td>
  114. {% endfor %}
  115. </tr>
  116. {% endfor %}
  117. </tbody>
  118. </table>