views-view-table.html.twig 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: 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. * @ingroup themeable
  34. */
  35. #}
  36. {%
  37. set classes = [
  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>