table.html.twig

Same filename in this branch
  1. main core/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig
  2. main core/themes/stable9/templates/dataset/table.html.twig
  3. main core/themes/claro/templates/classy/dataset/table.html.twig
  4. main core/themes/starterkit_theme/templates/dataset/table.html.twig
  5. main core/modules/system/templates/table.html.twig
Same filename and directory in other branches
  1. 10 core/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig
  2. 10 core/themes/stable9/templates/dataset/table.html.twig
  3. 10 core/themes/claro/templates/classy/dataset/table.html.twig
  4. 10 core/themes/starterkit_theme/templates/dataset/table.html.twig
  5. 11.x core/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig
  6. 11.x core/themes/stable9/templates/dataset/table.html.twig
  7. 11.x core/themes/claro/templates/classy/dataset/table.html.twig
  8. 11.x core/themes/starterkit_theme/templates/dataset/table.html.twig
  9. 11.x core/modules/system/templates/table.html.twig
  10. 10 core/modules/system/templates/table.html.twig
  11. 9 core/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig
  12. 9 core/themes/stable9/templates/dataset/table.html.twig
  13. 9 core/themes/seven/templates/classy/dataset/table.html.twig
  14. 9 core/themes/claro/templates/classy/dataset/table.html.twig
  15. 9 core/themes/bartik/templates/classy/dataset/table.html.twig
  16. 9 core/themes/stable/templates/dataset/table.html.twig
  17. 9 core/themes/starterkit_theme/templates/dataset/table.html.twig
  18. 9 core/themes/classy/templates/dataset/table.html.twig
  19. 9 core/modules/system/templates/table.html.twig
  20. 8.9.x core/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig
  21. 8.9.x core/themes/seven/templates/classy/dataset/table.html.twig
  22. 8.9.x core/themes/claro/templates/classy/dataset/table.html.twig
  23. 8.9.x core/themes/bartik/templates/classy/dataset/table.html.twig
  24. 8.9.x core/themes/stable/templates/dataset/table.html.twig
  25. 8.9.x core/themes/classy/templates/dataset/table.html.twig
  26. 8.9.x core/modules/system/templates/table.html.twig
  27. 11.x core/themes/admin/templates/dataset/table.html.twig

Theme override to display a table.

Available variables:

  • attributes: HTML attributes to apply to the <table> tag.
  • caption: A localized string for the <caption> tag.
  • colgroups: Column groups. Each group contains the following properties:
    • attributes: HTML attributes to apply to the <col> tag. Note: Drupal currently supports only one table header row.
  • header: Table header cells. Each cell contains the following properties:
    • tag: The HTML tag name to use; either 'th' or 'td'.
    • attributes: HTML attributes to apply to the tag.
    • content: A localized string for the title of the column.
    • field: Field name (required for column sorting).
    • sort: Default sort order for this column ("asc" or "desc").
  • sticky: A flag indicating whether to use a "sticky" table header.
  • rows: Table rows. Each row contains the following properties:
    • attributes: HTML attributes to apply to the <tr> tag.
    • data: Table cells.
    • no_striping: A flag indicating that the row should receive no 'even / odd' styling. Defaults to FALSE.
    • cells: Table cells of the row. Each cell contains the following keys:
      • tag: The HTML tag name to use; either 'th' or 'td'.
      • attributes: Any HTML attributes, such as "colspan", to apply to the table cell.
      • content: The string to display in the table cell.
      • active_table_sort: A boolean indicating whether the cell is the active table sort.
  • footer: Table footer rows, in the same format as the rows variable.
  • empty: The message to display in an extra row if table does not have any rows.
  • no_striping: A boolean indicating that the row should receive no striping.
  • header_columns: The number of columns in the header.

See also

template_preprocess_table()

9 theme calls to table.html.twig
ContentTranslationController::overview in core/modules/content_translation/src/Controller/ContentTranslationController.php
Builds the translations overview page.
MenuForm::buildOverviewForm in core/modules/menu_ui/src/MenuForm.php
Form constructor to edit an entire menu tree at once.
NodeController::revisionOverview in core/modules/node/src/Controller/NodeController.php
Generates an overview table of older revisions of a node.
PagerTestController::buildTestTable in core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php
Builds a render array for a multi-page test table.
Table::getInfo in core/lib/Drupal/Core/Render/Element/Table.php

... See full list

File

core/themes/admin/templates/dataset/table.html.twig

View source
  1. {#
  2. /* cspell:ignore syncscroll */
  3. /**
  4. * @file
  5. * Theme override to display a table.
  6. *
  7. * Available variables:
  8. * - attributes: HTML attributes to apply to the <table> tag.
  9. * - caption: A localized string for the <caption> tag.
  10. * - colgroups: Column groups. Each group contains the following properties:
  11. * - attributes: HTML attributes to apply to the <col> tag.
  12. * Note: Drupal currently supports only one table header row.
  13. * - header: Table header cells. Each cell contains the following properties:
  14. * - tag: The HTML tag name to use; either 'th' or 'td'.
  15. * - attributes: HTML attributes to apply to the tag.
  16. * - content: A localized string for the title of the column.
  17. * - field: Field name (required for column sorting).
  18. * - sort: Default sort order for this column ("asc" or "desc").
  19. * - sticky: A flag indicating whether to use a "sticky" table header.
  20. * - rows: Table rows. Each row contains the following properties:
  21. * - attributes: HTML attributes to apply to the <tr> tag.
  22. * - data: Table cells.
  23. * - no_striping: A flag indicating that the row should receive no
  24. * 'even / odd' styling. Defaults to FALSE.
  25. * - cells: Table cells of the row. Each cell contains the following keys:
  26. * - tag: The HTML tag name to use; either 'th' or 'td'.
  27. * - attributes: Any HTML attributes, such as "colspan", to apply to the
  28. * table cell.
  29. * - content: The string to display in the table cell.
  30. * - active_table_sort: A boolean indicating whether the cell is the active
  31. table sort.
  32. * - footer: Table footer rows, in the same format as the rows variable.
  33. * - empty: The message to display in an extra row if table does not have
  34. * any rows.
  35. * - no_striping: A boolean indicating that the row should receive no striping.
  36. * - header_columns: The number of columns in the header.
  37. *
  38. * @see template_preprocess_table()
  39. */
  40. #}
  41. {% import _self as macros %}
  42. {% macro table_header(header) %}
  43. <thead>
  44. <tr>
  45. {% for cell in header %}
  46. {% if '<a' in cell.content|render|render %}
  47. {%
  48. set cell_classes = [
  49. 'th__item',
  50. cell.active_table_sort ? 'is-active',
  51. 'select-all' in cell.attributes ? 'gin--sticky-bulk-select',
  52. ]
  53. %}
  54. {% else %}
  55. {%
  56. set cell_classes = [
  57. cell.content|render|clean_class ? 'th__' ~ cell.content|render|clean_class,
  58. cell.active_table_sort ? 'is-active',
  59. 'select-all' in cell.attributes ? 'gin--sticky-bulk-select',
  60. ]
  61. %}
  62. {% endif %}
  63. <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}>
  64. {{- cell.content -}}
  65. {% if 'gin--sticky-bulk-select' in cell_classes %}
  66. <input
  67. type="checkbox"
  68. class="form-checkbox form-boolean form-boolean--type-checkbox"
  69. title="{{ 'Select all rows in this table'|t }}"
  70. />
  71. {% endif %}
  72. </{{ cell.tag }}>
  73. {% endfor %}
  74. </tr>
  75. </thead>
  76. {% endmacro %}
  77. <div class="layer-wrapper gin-layer-wrapper">
  78. {% if header %}
  79. {% if sticky %}
  80. <table class="gin--sticky-table-header syncscroll" name="gin-sticky-header" hidden>
  81. {{ macros.table_header(header) }}
  82. </table>
  83. {% endif %}
  84. <div class="gin-table-scroll-wrapper gin-horizontal-scroll-shadow syncscroll" name="gin-sticky-header">
  85. {% endif %}
  86. <table{{ attributes }}>
  87. {% if caption %}
  88. <caption>{{ caption }}</caption>
  89. {% endif %}
  90. {% for colgroup in colgroups %}
  91. {% if colgroup.cols %}
  92. <colgroup{{ colgroup.attributes }}>
  93. {% for col in colgroup.cols %}
  94. <col{{ col.attributes }} />
  95. {% endfor %}
  96. </colgroup>
  97. {% else %}
  98. <colgroup{{ colgroup.attributes }} />
  99. {% endif %}
  100. {% endfor %}
  101. {% if header %}
  102. {{ macros.table_header(header) }}
  103. {% endif %}
  104. {% if rows %}
  105. <tbody>
  106. {% for row in rows %}
  107. {%
  108. set row_classes = [
  109. not no_striping ? cycle(['odd', 'even'], loop.index0),
  110. ]
  111. %}
  112. <tr{{ row.attributes.addClass(row_classes) }}>
  113. {% for cell in row.cells %}
  114. <{{ cell.tag }}{{ cell.attributes }}>
  115. {{- cell.content -}}
  116. </{{ cell.tag }}>
  117. {% endfor %}
  118. </tr>
  119. {% endfor %}
  120. </tbody>
  121. {% elseif empty %}
  122. <tbody>
  123. <tr class="odd">
  124. <td colspan="{{ header_columns }}" class="empty message">{{ empty }}</td>
  125. </tr>
  126. </tbody>
  127. {% endif %}
  128. {% if footer %}
  129. <tfoot>
  130. {% for row in footer %}
  131. <tr{{ row.attributes }}>
  132. {% for cell in row.cells %}
  133. <{{ cell.tag }}{{ cell.attributes }}>
  134. {{- cell.content -}}
  135. </{{ cell.tag }}>
  136. {% endfor %}
  137. </tr>
  138. {% endfor %}
  139. </tfoot>
  140. {% endif %}
  141. </table>
  142. {% if header %}
  143. </div>
  144. {% endif %}
  145. </div>

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.