table--simple.html.twig

Same filename and directory in other branches
  1. main core/themes/admin/templates/dataset/table--simple.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()

File

core/themes/admin/templates/dataset/table--simple.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.
  12. * - header: Table header cells. Each cell contains the following properties:
  13. * - tag: The HTML tag name to use; either 'th' or 'td'.
  14. * - attributes: HTML attributes to apply to the tag.
  15. * - content: A localized string for the title of the column.
  16. * - field: Field name (required for column sorting).
  17. * - sort: Default sort order for this column ("asc" or "desc").
  18. * - sticky: A flag indicating whether to use a "sticky" table header.
  19. * - rows: Table rows. Each row contains the following properties:
  20. * - attributes: HTML attributes to apply to the <tr> tag.
  21. * - data: Table cells.
  22. * - no_striping: A flag indicating that the row should receive no
  23. * 'even / odd' styling. Defaults to FALSE.
  24. * - cells: Table cells of the row. Each cell contains the following keys:
  25. * - tag: The HTML tag name to use; either 'th' or 'td'.
  26. * - attributes: Any HTML attributes, such as "colspan", to apply to the
  27. * table cell.
  28. * - content: The string to display in the table cell.
  29. * - active_table_sort: A boolean indicating whether the cell is the active
  30. table sort.
  31. * - footer: Table footer rows, in the same format as the rows variable.
  32. * - empty: The message to display in an extra row if table does not have
  33. * any rows.
  34. * - no_striping: A boolean indicating that the row should receive no striping.
  35. * - header_columns: The number of columns in the header.
  36. *
  37. * @see template_preprocess_table()
  38. */
  39. #}
  40. <table{{ attributes }}>
  41. {% if caption %}
  42. <caption>{{ caption }}</caption>
  43. {% endif %}
  44. {% for colgroup in colgroups %}
  45. {% if colgroup.cols %}
  46. <colgroup{{ colgroup.attributes }}>
  47. {% for col in colgroup.cols %}
  48. <col{{ col.attributes }} />
  49. {% endfor %}
  50. </colgroup>
  51. {% else %}
  52. <colgroup{{ colgroup.attributes }} />
  53. {% endif %}
  54. {% endfor %}
  55. {% if header %}
  56. <thead>
  57. <tr>
  58. {% for cell in header %}
  59. {%
  60. set cell_classes = [
  61. cell.active_table_sort ? 'is-active',
  62. ]
  63. %}
  64. <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}>
  65. {{- cell.content -}}
  66. </{{ cell.tag }}>
  67. {% endfor %}
  68. </tr>
  69. </thead>
  70. {% endif %}
  71. {% if rows %}
  72. <tbody>
  73. {% for row in rows %}
  74. {%
  75. set row_classes = [
  76. not no_striping ? cycle(['odd', 'even'], loop.index0),
  77. ]
  78. %}
  79. <tr{{ row.attributes.addClass(row_classes) }}>
  80. {% for cell in row.cells %}
  81. <{{ cell.tag }}{{ cell.attributes }}>
  82. {{- cell.content -}}
  83. </{{ cell.tag }}>
  84. {% endfor %}
  85. </tr>
  86. {% endfor %}
  87. </tbody>
  88. {% elseif empty %}
  89. <tbody>
  90. <tr class="odd">
  91. <td colspan="{{ header_columns }}" class="empty message">{{ empty }}</td>
  92. </tr>
  93. </tbody>
  94. {% endif %}
  95. {% if footer %}
  96. <tfoot>
  97. {% for row in footer %}
  98. <tr{{ row.attributes }}>
  99. {% for cell in row.cells %}
  100. <{{ cell.tag }}{{ cell.attributes }}>
  101. {{- cell.content -}}
  102. </{{ cell.tag }}>
  103. {% endfor %}
  104. </tr>
  105. {% endfor %}
  106. </tfoot>
  107. {% endif %}
  108. </table>

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