You are here

uikit-view-table.html.twig in UIkit Components 8

Default theme implementation for displaying a view as a table.

Available variables:

  • attributes: Remaining HTML attributes for the element.

    • class: HTML classes that can be used to style contextually through CSS.
  • title : The title of this group of rows.
  • header: The table header columns.
    • attributes: Remaining HTML attributes for the element.
    • content: HTML classes to apply to each header cell, indexed by

    the header's key.

    • default_classes: A flag indicating whether default classes should be used.
  • caption_needed: Is the caption tag needed.
  • caption: The caption for this table.
  • accessibility_description: Extended description for the table details.
  • accessibility_summary: Summary for the table details.
  • rows: Table row items. Rows are keyed by row number.
    • attributes: HTML classes to apply to each row.
    • columns: Row column items. Columns are keyed by column number.
      • attributes: HTML classes to apply to each column.
      • content: The column content.
    • default_classes: A flag indicating whether default classes should be used.
  • responsive: A flag indicating whether table is responsive.
  • sticky: A flag indicating whether table header is sticky.

File

uikit_views/templates/views/uikit-view-table.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for displaying a view as a table.
  5. *
  6. * Available variables:
  7. * - attributes: Remaining HTML attributes for the element.
  8. * - class: HTML classes that can be used to style contextually through CSS.
  9. * - title : The title of this group of rows.
  10. * - header: The table header columns.
  11. * - attributes: Remaining HTML attributes for the element.
  12. * - content: HTML classes to apply to each header cell, indexed by
  13. * the header's key.
  14. * - default_classes: A flag indicating whether default classes should be
  15. * used.
  16. * - caption_needed: Is the caption tag needed.
  17. * - caption: The caption for this table.
  18. * - accessibility_description: Extended description for the table details.
  19. * - accessibility_summary: Summary for the table details.
  20. * - rows: Table row items. Rows are keyed by row number.
  21. * - attributes: HTML classes to apply to each row.
  22. * - columns: Row column items. Columns are keyed by column number.
  23. * - attributes: HTML classes to apply to each column.
  24. * - content: The column content.
  25. * - default_classes: A flag indicating whether default classes should be
  26. * used.
  27. * - responsive: A flag indicating whether table is responsive.
  28. * - sticky: A flag indicating whether table header is sticky.
  29. *
  30. * @see template_preprocess_views_view_table()
  31. * @see template_preprocess_uikit_view_table()
  32. *
  33. * @ingroup themeable
  34. */
  35. #}
  36. {%
  37. set classes = [
  38. 'uk-table',
  39. hover ? 'uk-table-hover',
  40. striped ? 'uk-table-striped',
  41. condensed ? 'uk-table-condensed',
  42. 'cols-' ~ header|length,
  43. responsive ? 'responsive-enabled',
  44. sticky ? 'sticky-enabled',
  45. ]
  46. %}
  47. {% if responsive_table %}
  48. <div class="uk-overflow-container">
  49. {% endif %}
  50. <table{{ attributes.addClass(classes) }}>
  51. {% if caption_needed %}
  52. <caption>
  53. {% if caption %}
  54. {{ caption }}
  55. {% else %}
  56. {{ title }}
  57. {% endif %}
  58. {% if (summary is not empty) or (description is not empty) %}
  59. <details>
  60. {% if summary is not empty %}
  61. <summary>{{ summary }}</summary>
  62. {% endif %}
  63. {% if description is not empty %}
  64. {{ description }}
  65. {% endif %}
  66. </details>
  67. {% endif %}
  68. </caption>
  69. {% endif %}
  70. {% if header %}
  71. <thead>
  72. <tr{{ table_row_attributes }}>
  73. {% for key, column in header %}
  74. {% if column.default_classes %}
  75. {%
  76. set column_classes = [
  77. 'views-field',
  78. 'views-field-' ~ fields[key],
  79. ]
  80. %}
  81. {% endif %}
  82. <th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
  83. {%- if column.wrapper_element -%}
  84. <{{ column.wrapper_element }}>
  85. {%- if column.url -%}
  86. <a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
  87. {%- else -%}
  88. {{ column.content }}{{ column.sort_indicator }}
  89. {%- endif -%}
  90. </{{ column.wrapper_element }}>
  91. {%- else -%}
  92. {%- if column.url -%}
  93. <a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
  94. {%- else -%}
  95. {{- column.content }}{{ column.sort_indicator }}
  96. {%- endif -%}
  97. {%- endif -%}
  98. </th>
  99. {% endfor %}
  100. </tr>
  101. </thead>
  102. {% endif %}
  103. <tbody>
  104. {% for row in rows %}
  105. {% set row_classes = [vertical_modifier ? 'uk-table-middle'] %}
  106. <tr{{ row.attributes.addClass(row_classes) }}>
  107. {% for key, column in row.columns %}
  108. {% if column.default_classes %}
  109. {%
  110. set column_classes = [
  111. 'views-field'
  112. ]
  113. %}
  114. {% for field in column.fields %}
  115. {% set column_classes = column_classes|merge(['views-field-' ~ field]) %}
  116. {% endfor %}
  117. {% endif %}
  118. <td{{ column.attributes.addClass(column_classes) }}>
  119. {%- if column.wrapper_element -%}
  120. <{{ column.wrapper_element }}>
  121. {% for content in column.content %}
  122. {{ content.separator }}{{ content.field_output }}
  123. {% endfor %}
  124. </{{ column.wrapper_element }}>
  125. {%- else -%}
  126. {% for content in column.content %}
  127. {{- content.separator }}{{ content.field_output -}}
  128. {% endfor %}
  129. {%- endif %}
  130. </td>
  131. {% endfor %}
  132. </tr>
  133. {% endfor %}
  134. </tbody>
  135. </table>
  136. {% if responsive_table %}
  137. </div>
  138. {% endif %}