file table.html.twig

Default theme implementation to display a table.

Available variables:

  • attributes: HTML attributes to apply to the tag.
  • caption: A localized string for the
  • tag. Note: Drupal currently supports only one table header row, see http://drupal.org/node/893530 and http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_table....
  • 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
  • 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.
  • header_columns: The number of columns in the header.
  • bordered: Flag indicating whether or not the table should be bordered.
  • condensed: Flag indicating whether or not the table should be condensed.
  • hover: Flag indicating whether or not table rows should be hoverable.
  • striped: Flag indicating whether or not table rows should be striped.
  • responsive: Flag indicating whether or not the table should be wrapped to be responsive (using the Bootstrap Framework .table-responsive wrapper).
  • See Also

    • template_preprocess_table()
    Source
    1. {#
    2. /**
    3. * @file
    4. * Default theme implementation 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. * http://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. * - footer: Table footer rows, in the same format as the rows variable.
    34. * - empty: The message to display in an extra row if table does not have
    35. * any rows.
    36. * - header_columns: The number of columns in the header.
    37. * - bordered: Flag indicating whether or not the table should be bordered.
    38. * - condensed: Flag indicating whether or not the table should be condensed.
    39. * - hover: Flag indicating whether or not table rows should be hoverable.
    40. * - striped: Flag indicating whether or not table rows should be striped.
    41. * - responsive: Flag indicating whether or not the table should be wrapped to
    42. * be responsive (using the Bootstrap Framework .table-responsive wrapper).
    43. *
    44. * @ingroup templates
    45. *
    46. * @see template_preprocess_table()
    47. */
    48. #}
    49. {% if responsive %}
    50. <div class="table-responsive">
    51. {% endif %}
    52. {%
    53. set classes = [
    54. 'table',
    55. bordered ? 'table-bordered',
    56. condensed ? 'table-condensed',
    57. hover ? 'table-hover',
    58. striped ? 'table-striped',
    59. sticky ? 'sticky-enabled',
    60. ]
    61. %}
    62. <table{{ attributes.addClass(classes) }}>
    63. {% if caption %}
    64. <caption>{{ caption }}</caption>
    65. {% endif %}
    66. {% for colgroup in colgroups %}
    67. {% if colgroup.cols %}
    68. <colgroup{{ colgroup.attributes }}>
    69. {% for col in colgroup.cols %}
    70. <col{{ col.attributes }} />
    71. {% endfor %}
    72. </colgroup>
    73. {% else %}
    74. <colgroup{{ colgroup.attributes }} />
    75. {% endif %}
    76. {% endfor %}
    77. {% if header %}
    78. <thead>
    79. <tr>
    80. {% for cell in header %}
    81. {%
    82. set cell_classes = [
    83. cell.active_table_sort ? 'active',
    84. ]
    85. %}
    86. <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}>
    87. {{- cell.content -}}
    88. </{{ cell.tag }}>
    89. {% endfor %}
    90. </tr>
    91. </thead>
    92. {% endif %}
    93. {% if rows %}
    94. <tbody>
    95. {% for row in rows %}
    96. {% set row_classes = [cycle(['odd', 'even'], loop.index0)] %}
    97. <tr{{ row.attributes.addClass(row_classes) }}>
    98. {% for cell in row.cells %}
    99. <{{ cell.tag }}{{ cell.attributes }}>
    100. {{- cell.content -}}
    101. </{{ cell.tag }}>
    102. {% endfor %}
    103. </tr>
    104. {% endfor %}
    105. </tbody>
    106. {% elseif empty %}
    107. <tbody>
    108. <tr class="odd">
    109. <td colspan="{{ header_columns }}" class="empty message">{{ empty }}</td>
    110. </tr>
    111. </tbody>
    112. {% endif %}
    113. {% if footer %}
    114. <tfoot>
    115. {% for row in footer %}
    116. <tr{{ row.attributes }}>
    117. {% for cell in row.cells %}
    118. <{{ cell.tag }}{{ cell.attributes }}>
    119. {{- cell.content -}}
    120. </{{ cell.tag }}>
    121. {% endfor %}
    122. </tr>
    123. {% endfor %}
    124. </tfoot>
    125. {% endif %}
    126. </table>
    127. {% if responsive %}
    128. </div>
    129. {% endif %}

    Related topics

    tag.
  • colgroups: Column groups. Each group contains the following properties:
    • attributes: HTML attributes to apply to the