You are here

views-view-table.html.twig in Zircon Profile 8.0

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.

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