table.html.twig

Same filename in this branch
  1. 10 core/themes/stable9/templates/dataset/table.html.twig
  2. 10 core/themes/claro/templates/classy/dataset/table.html.twig
  3. 10 core/themes/starterkit_theme/templates/dataset/table.html.twig
  4. 10 core/modules/system/templates/table.html.twig
Same filename in other branches
  1. 9 core/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig
  2. 9 core/themes/stable9/templates/dataset/table.html.twig
  3. 9 core/themes/seven/templates/classy/dataset/table.html.twig
  4. 9 core/themes/claro/templates/classy/dataset/table.html.twig
  5. 9 core/themes/bartik/templates/classy/dataset/table.html.twig
  6. 9 core/themes/stable/templates/dataset/table.html.twig
  7. 9 core/themes/starterkit_theme/templates/dataset/table.html.twig
  8. 9 core/themes/classy/templates/dataset/table.html.twig
  9. 9 core/modules/system/templates/table.html.twig
  10. 8.9.x core/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig
  11. 8.9.x core/themes/seven/templates/classy/dataset/table.html.twig
  12. 8.9.x core/themes/claro/templates/classy/dataset/table.html.twig
  13. 8.9.x core/themes/bartik/templates/classy/dataset/table.html.twig
  14. 8.9.x core/themes/stable/templates/dataset/table.html.twig
  15. 8.9.x core/themes/classy/templates/dataset/table.html.twig
  16. 8.9.x core/modules/system/templates/table.html.twig
  17. 11.x core/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig
  18. 11.x core/themes/stable9/templates/dataset/table.html.twig
  19. 11.x core/themes/claro/templates/classy/dataset/table.html.twig
  20. 11.x core/themes/starterkit_theme/templates/dataset/table.html.twig
  21. 11.x core/modules/system/templates/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:
  • 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.
      • header: Boolean indicating whether the cell should be rendered as a header (<th>) or not (<td>).
  • 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()

10 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/profiles/demo_umami/themes/umami/templates/classy/dataset/table.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override to display a table.
  5. *
  6. * Available variables:
  7. * - attributes: HTML attributes to apply to the <table> tag.
  8. * - caption: A localized string for the <caption> tag.
  9. * - colgroups: Column groups. Each group contains the following properties:
  10. * - attributes: HTML attributes to apply to the <col> tag.
  11. * Note: Drupal currently supports only one table header row, see
  12. * https://www.drupal.org/node/893530 and
  13. * http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_table/7#comment-5109.
  14. * - header: Table header cells. Each cell contains the following properties:
  15. * - tag: The HTML tag name to use; either 'th' or 'td'.
  16. * - attributes: HTML attributes to apply to the tag.
  17. * - content: A localized string for the title of the column.
  18. * - field: Field name (required for column sorting).
  19. * - sort: Default sort order for this column ("asc" or "desc").
  20. * - sticky: A flag indicating whether to use a "sticky" table header.
  21. * - rows: Table rows. Each row contains the following properties:
  22. * - attributes: HTML attributes to apply to the <tr> tag.
  23. * - data: Table cells.
  24. * - no_striping: A flag indicating that the row should receive no
  25. * 'even / odd' styling. Defaults to FALSE.
  26. * - cells: Table cells of the row. Each cell contains the following keys:
  27. * - tag: The HTML tag name to use; either 'th' or 'td'.
  28. * - attributes: Any HTML attributes, such as "colspan", to apply to the
  29. * table cell.
  30. * - content: The string to display in the table cell.
  31. * - active_table_sort: A boolean indicating whether the cell is the active
  32. table sort.
  33. * - header: Boolean indicating whether the cell should be rendered as a
  34. * header (<th>) or not (<td>).
  35. * - footer: Table footer rows, in the same format as the rows variable.
  36. * - empty: The message to display in an extra row if table does not have
  37. * any rows.
  38. * - no_striping: A boolean indicating that the row should receive no striping.
  39. * - header_columns: The number of columns in the header.
  40. *
  41. * @see template_preprocess_table()
  42. */
  43. #}
  44. <table{{ attributes }}>
  45. {% if caption %}
  46. <caption>{{ caption }}</caption>
  47. {% endif %}
  48. {% for colgroup in colgroups %}
  49. {% if colgroup.cols %}
  50. <colgroup{{ colgroup.attributes }}>
  51. {% for col in colgroup.cols %}
  52. <col{{ col.attributes }} />
  53. {% endfor %}
  54. </colgroup>
  55. {% else %}
  56. <colgroup{{ colgroup.attributes }} />
  57. {% endif %}
  58. {% endfor %}
  59. {% if header %}
  60. <thead>
  61. <tr>
  62. {% for cell in header %}
  63. {%
  64. set cell_classes = [
  65. cell.active_table_sort ? 'is-active',
  66. ]
  67. %}
  68. <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}>
  69. {{- cell.content -}}
  70. </{{ cell.tag }}>
  71. {% endfor %}
  72. </tr>
  73. </thead>
  74. {% endif %}
  75. {% if rows %}
  76. <tbody>
  77. {% for row in rows %}
  78. {%
  79. set row_classes = [
  80. not no_striping ? cycle(['odd', 'even'], loop.index0),
  81. ]
  82. %}
  83. <tr{{ row.attributes.addClass(row_classes) }}>
  84. {% for cell in row.cells %}
  85. <{{ cell.tag }}{{ cell.attributes }}>
  86. {{- cell.content -}}
  87. </{{ cell.tag }}>
  88. {% endfor %}
  89. </tr>
  90. {% endfor %}
  91. </tbody>
  92. {% elseif empty %}
  93. <tbody>
  94. <tr class="odd">
  95. <td colspan="{{ header_columns }}" class="empty message">{{ empty }}</td>
  96. </tr>
  97. </tbody>
  98. {% endif %}
  99. {% if footer %}
  100. <tfoot>
  101. {% for row in footer %}
  102. <tr{{ row.attributes }}>
  103. {% for cell in row.cells %}
  104. <{{ cell.tag }}{{ cell.attributes }}>
  105. {{- cell.content -}}
  106. </{{ cell.tag }}>
  107. {% endfor %}
  108. </tr>
  109. {% endfor %}
  110. </tfoot>
  111. {% endif %}
  112. </table>

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