You are here

views-tree-table.html.twig in Views tree 8.2

Default theme implementation for displaying a view as a table.

Available variables (from core views_view_table):

  • 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.

Available variables from views tree:

  • items: A list of items. Each item contains:

    • attributes: HTML attributes to be applied to each list item.
    • value: The content of the list element.

File

templates/views-tree-table.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for displaying a view as a table.
  5. *
  6. * Available variables (from core views_view_table):
  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. * Available variables from views tree:
  31. * - items: A list of items. Each item contains:
  32. * - attributes: HTML attributes to be applied to each list item.
  33. * - value: The content of the list element.
  34. *
  35. * @see template_preprocess_views_tree_table()
  36. *
  37. * @ingroup themeable
  38. */
  39. #}
  40. {%
  41. set classes = [
  42. 'cols-' ~ header|length,
  43. responsive ? 'responsive-enabled',
  44. sticky ? 'sticky-enabled',
  45. ]
  46. %}
  47. {% import _self as views_tree %}
  48. <table{{ attributes.addClass(classes) }}>
  49. {% if caption_needed %}
  50. <caption>
  51. {% if caption %}
  52. {{ caption }}
  53. {% else %}
  54. {{ title }}
  55. {% endif %}
  56. {% if (summary is not empty) or (description is not empty) %}
  57. <details>
  58. {% if summary is not empty %}
  59. <summary>{{ summary }}</summary>
  60. {% endif %}
  61. {% if description is not empty %}
  62. {{ description }}
  63. {% endif %}
  64. </details>
  65. {% endif %}
  66. </caption>
  67. {% endif %}
  68. {% if header %}
  69. <thead>
  70. <tr>
  71. {% for key, column in header %}
  72. {% if column.default_classes %}
  73. {%
  74. set column_classes = [
  75. 'views-field',
  76. 'views-field-' ~ fields[key],
  77. ]
  78. %}
  79. {% endif %}
  80. <th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
  81. {%- if column.wrapper_element -%}
  82. <{{ column.wrapper_element }}>
  83. {%- if column.url -%}
  84. <a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
  85. {%- else -%}
  86. {{ column.content }}{{ column.sort_indicator }}
  87. {%- endif -%}
  88. </{{ column.wrapper_element }}>
  89. {%- else -%}
  90. {%- if column.url -%}
  91. <a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
  92. {%- else -%}
  93. {{- column.content }}{{ column.sort_indicator }}
  94. {%- endif -%}
  95. {%- endif -%}
  96. </th>
  97. {% endfor %}
  98. </tr>
  99. </thead>
  100. {% endif %}
  101. <tbody>
  102. {{ views_tree.tree(items) }}
  103. </tbody>
  104. </table>
  105. {% macro tree(items) %}
  106. {% import _self as views_tree %}
  107. {% if items %}
  108. {%- if items -%}
  109. {%- for item in items -%}
  110. {{ views_tree.row(item.node) }}
  111. {{ views_tree.tree(item.leaves) }}
  112. {% endfor %}
  113. {% endif %}
  114. {% endif %}
  115. {% endmacro %}
  116. {% macro row(item) %}
  117. <tr{{ item.attributes }}>
  118. {% for key, column in item.columns %}
  119. {% if column.default_classes %}
  120. {%
  121. set column_classes = [
  122. 'views-field'
  123. ]
  124. %}
  125. {% for field in column.fields %}
  126. {% set column_classes = column_classes|merge(['views-field-' ~ field]) %}
  127. {% endfor %}
  128. {% endif %}
  129. <td{{ column.attributes.addClass(column_classes) }}>
  130. {%- if column.wrapper_element -%}
  131. <{{ column.wrapper_element }}>
  132. {% for content in column.content %}
  133. {{ content.separator }}{{ content.field_output }}
  134. {% endfor %}
  135. </{{ column.wrapper_element }}>
  136. {%- else -%}
  137. {% for content in column.content %}
  138. {{- content.separator }}{{ content.field_output -}}
  139. {% endfor %}
  140. {%- endif %}
  141. </td>
  142. {% endfor %}
  143. </tr>
  144. {% endmacro %}