Drupal investigation

views-view-table.html.twig 4.2KB

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