You are here

table.html.twig in Open Social 8.3

Default theme implementation 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.
  • 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.

File

themes/socialbase/templates/system/table.html.twig
View 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. * - no_striping: A boolean indicating that the row should receive no striping.
  37. * - header_columns: The number of columns in the header.
  38. *
  39. * @see template_preprocess_table()
  40. *
  41. * @ingroup templates
  42. */
  43. #}
  44. <div class="table-responsive">
  45. {%
  46. set classes = [
  47. 'table',
  48. 'table-hover',
  49. 'table-striped',
  50. sticky ? 'sticky-enabled',
  51. ]
  52. %}
  53. <table{{ attributes.addClass(classes) }}>
  54. {% if caption %}
  55. <caption>{{ caption }}</caption>
  56. {% endif %}
  57. {% for colgroup in colgroups %}
  58. {% if colgroup.cols %}
  59. <colgroup{{ colgroup.attributes }}>
  60. {% for col in colgroup.cols %}
  61. <col{{ col.attributes }} />
  62. {% endfor %}
  63. </colgroup>
  64. {% else %}
  65. <colgroup{{ colgroup.attributes }} />
  66. {% endif %}
  67. {% endfor %}
  68. {% if header %}
  69. <thead>
  70. <tr>
  71. {% for cell in header %}
  72. {%
  73. set cell_classes = [
  74. cell.active_table_sort ? 'active',
  75. ]
  76. %}
  77. <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}>
  78. {{- cell.content -}}
  79. </{{ cell.tag }}>
  80. {% endfor %}
  81. </tr>
  82. </thead>
  83. {% endif %}
  84. {% if rows %}
  85. <tbody>
  86. {% for row in rows %}
  87. {%
  88. set row_classes = [
  89. not no_striping ? cycle(['odd', 'even'], loop.index0),
  90. ]
  91. %}
  92. <tr{{ row.attributes.addClass(row_classes) }}>
  93. {% for cell in row.cells %}
  94. <{{ cell.tag }}{{ cell.attributes }}>
  95. {{- cell.content -}}
  96. </{{ cell.tag }}>
  97. {% endfor %}
  98. </tr>
  99. {% endfor %}
  100. </tbody>
  101. {% elseif empty %}
  102. <tbody>
  103. <tr class="odd">
  104. <td colspan="{{ header_columns }}" class="empty message">{{ empty }}</td>
  105. </tr>
  106. </tbody>
  107. {% endif %}
  108. {% if footer %}
  109. <tfoot>
  110. {% for row in footer %}
  111. <tr{{ row.attributes }}>
  112. {% for cell in row.cells %}
  113. <{{ cell.tag }}{{ cell.attributes }}>
  114. {{- cell.content -}}
  115. </{{ cell.tag }}>
  116. {% endfor %}
  117. </tr>
  118. {% endfor %}
  119. </tfoot>
  120. {% endif %}
  121. </table>
  122. </div>