You are here

views-aggregator-results-table.html.twig in Views Aggregator Plus 8

Template to display views results after aggregation as a table.

This template is based on the one in the Views module: views/templates/views-view-table.html.twig

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.
  • bordered: Flag indicating whether or not the table should be bordered (Bootstrap).
  • condensed: Flag indicating whether or not the table should be condensed (Bootstrap).
  • hover: Flag indicating whether or not table rows should be hoverable (Bootstrap).
  • striped: Flag indicating whether or not table rows should be striped (Bootstrap).
  • responsive: A flag indicating whether table is responsive.
  • sticky: A flag indicating whether table header is sticky.
  • grouping_field: The field with the function Group & Compress applied.
  • group_aggregation_results: Whether to output results as subtotals.
  • grouping_row_class: A class to apply to cells in the group aggregation row.
  • grouping_field_class: A class to apply to cells in the group aggregation column.
  • totals: an array with field name as key and the value to show in the table footer as value
  • totals_row_position: whether to show the totals row at top, bottom or both
  • totals_row_class: A class to apply to the column aggregation row.

File

templates/views-aggregator-results-table.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Template to display views results after aggregation as a table.
  5. *
  6. * This template is based on the one in the Views module:
  7. * views/templates/views-view-table.html.twig
  8. *
  9. * Available variables:
  10. * - attributes: Remaining HTML attributes for the element.
  11. * - class: HTML classes that can be used to style contextually through CSS.
  12. * - title : The title of this group of rows.
  13. * - header: The table header columns.
  14. * - attributes: Remaining HTML attributes for the element.
  15. * - content: HTML classes to apply to each header cell, indexed by
  16. * the header's key.
  17. * - default_classes: A flag indicating whether default classes should be
  18. * used.
  19. * - caption_needed: Is the caption tag needed.
  20. * - caption: The caption for this table.
  21. * - accessibility_description: Extended description for the table details.
  22. * - accessibility_summary: Summary for the table details.
  23. * - rows: Table row items. Rows are keyed by row number.
  24. * - attributes: HTML classes to apply to each row.
  25. * - columns: Row column items. Columns are keyed by column number.
  26. * - attributes: HTML classes to apply to each column.
  27. * - content: The column content.
  28. * - default_classes: A flag indicating whether default classes should be
  29. * used.
  30. * - bordered: Flag indicating whether or not the table should be bordered (Bootstrap).
  31. * - condensed: Flag indicating whether or not the table should be condensed (Bootstrap).
  32. * - hover: Flag indicating whether or not table rows should be hoverable (Bootstrap).
  33. * - striped: Flag indicating whether or not table rows should be striped (Bootstrap).
  34. * - responsive: A flag indicating whether table is responsive.
  35. * - sticky: A flag indicating whether table header is sticky.
  36. * - grouping_field: The field with the function Group & Compress applied.
  37. * - group_aggregation_results: Whether to output results as subtotals.
  38. * - grouping_row_class: A class to apply to cells in the group aggregation row.
  39. * - grouping_field_class: A class to apply to cells in the group aggregation column.
  40. * - totals: an array with field name as key and the value to show in the table footer as value
  41. * - totals_row_position: whether to show the totals row at top, bottom or both
  42. * - totals_row_class: A class to apply to the column aggregation row.
  43. * @see template_preprocess_views_view_table()
  44. *
  45. * @ingroup themeable
  46. */
  47. #}
  48. {% if responsive %}
  49. <div class="table-responsive">
  50. {% endif %}
  51. {%
  52. set classes = [
  53. 'table',
  54. 'cols-' ~ header|length,
  55. bordered ? 'table-bordered',
  56. condensed ? 'table-condensed',
  57. hover ? 'table-hover',
  58. striped ? 'table-striped',
  59. responsive ? 'responsive-enabled',
  60. sticky ? 'sticky-enabled',
  61. ]
  62. %}
  63. {% set totals_attributes = create_attribute() %}
  64. <table{{ attributes.addClass(classes) }}>
  65. {% if caption_needed %}
  66. <caption>
  67. {% if caption %}
  68. {{ caption }}
  69. {% else %}
  70. {{ title }}
  71. {% endif %}
  72. {% if (summary is not empty) or (description is not empty) %}
  73. <details>
  74. {% if summary is not empty %}
  75. <summary>{{ summary }}</summary>
  76. {% endif %}
  77. {% if description is not empty %}
  78. {{ description }}
  79. {% endif %}
  80. </details>
  81. {% endif %}
  82. </caption>
  83. {% endif %}
  84. {% if header %}
  85. <thead>
  86. <tr>
  87. {% for key, column in header %}
  88. {% if column.default_classes %}
  89. {%
  90. set column_classes = [
  91. 'views-field',
  92. 'views-field-' ~ fields[key],
  93. ]
  94. %}
  95. {% endif %}
  96. <th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
  97. {%- if column.wrapper_element -%}
  98. <{{ column.wrapper_element }}>
  99. {%- if column.url -%}
  100. <a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
  101. {%- else -%}
  102. {{ column.content }}{{ column.sort_indicator }}
  103. {%- endif -%}
  104. </{{ column.wrapper_element }}>
  105. {%- else -%}
  106. {%- if column.url -%}
  107. <a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
  108. {%- else -%}
  109. {{- column.content }}{{ column.sort_indicator }}
  110. {%- endif -%}
  111. {%- endif -%}
  112. </th>
  113. {% endfor %}
  114. </tr>
  115. {% if totals and totals_row_position in [1,3] %}
  116. <tr{{ totals_attributes.addClass(totals_row_class) }}>
  117. {% for key, column in header %}
  118. {% if attribute(totals, key) %}
  119. {% if grouping_field and grouping_field_class and grouping_field == key %}
  120. <td{{ column.attributes.addClass(column_classes).addClass(grouping_field_class) }}>{{ attribute(totals, key) }}</td>
  121. {% else %}
  122. <td{{ column.attributes.addClass(column_classes) }}>{{ attribute(totals, key) }}</td>
  123. {% endif %}
  124. {% else %}
  125. <td{{ column.attributes.addClass(column_classes) }}></td>
  126. {% endif %}
  127. {% endfor %}
  128. </tr>
  129. {% endif %}
  130. </thead>
  131. {% endif %}
  132. <tbody>
  133. {% for row in rows %}
  134. <tr{{ row.attributes }}>
  135. {% for key, column in row.columns %}
  136. {% if column.default_classes %}
  137. {%
  138. set column_classes = [
  139. 'views-field'
  140. ]
  141. %}
  142. {% for field in column.fields %}
  143. {% set column_classes = column_classes|merge(['views-field-' ~ field]) %}
  144. {% if grouping_field and grouping_field_class and grouping_field == key %}
  145. {% set column_classes = column_classes|merge([grouping_field_class]) %}
  146. {% endif %}
  147. {% endfor %}
  148. {% endif %}
  149. <td{{ column.attributes.addClass(column_classes) }}>
  150. {%- if column.wrapper_element -%}
  151. <{{ column.wrapper_element }}>
  152. {% for content in column.content %}
  153. {{ content.separator }}{{ content.field_output }}
  154. {% endfor %}
  155. </{{ column.wrapper_element }}>
  156. {%- else -%}
  157. {% for content in column.content %}
  158. {{- content.separator }}{{ content.field_output -}}
  159. {% endfor %}
  160. {%- endif %}
  161. </td>
  162. {% endfor %}
  163. </tr>
  164. {% if loop.index0 in subtotals|keys %}
  165. {% set row_number = loop.index0 %}
  166. <tr{{ row.attributes.addClass(grouping_row_class) }}>
  167. {% for key, column in header %}
  168. {% if attribute(subtotals[row_number], key) %}
  169. {% if grouping_field and grouping_field_class and grouping_field == key %}
  170. <td{{ column.attributes.addClass(column_classes).addClass(grouping_field_class) }}>{{ attribute(subtotals[row_number], key) }}</td>
  171. {% else %}
  172. <td{{ column.attributes.addClass(column_classes) }}>{{ attribute(subtotals[row_number], key) }}</td>
  173. {% endif %}
  174. {% else %}
  175. <td{{ column.attributes.addClass(column_classes) }}></td>
  176. {% endif %}
  177. {% endfor %}
  178. </tr>
  179. {% endif %}
  180. {% endfor %}
  181. </tbody>
  182. {% if totals and totals_row_position in [2,3] %}
  183. <tfoot>
  184. <tr{{ totals_attributes.addClass(totals_row_class) }}>
  185. {% for key, column in header %}
  186. {% if attribute(totals, key) %}
  187. <td{{ column.attributes.addClass(column_classes) }}>{{ attribute(totals, key) }}</td>
  188. {% else %}
  189. <td{{ column.attributes.addClass(column_classes) }}></td>
  190. {% endif %}
  191. {% endfor %}
  192. </tr>
  193. </tfoot>
  194. {% endif %}
  195. </table>
  196. {% if responsive %}
  197. </div>
  198. {% endif %}