You are here

views-bootstrap-table.html.twig in Views Bootstrap 8.3

Same filename and directory in other branches
  1. 8.4 templates/views-bootstrap-table.html.twig

Default theme implementation for displaying a view as a bootstrap 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

templates/views-bootstrap-table.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for displaying a view as a bootstrap 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_bootstrap_table()
  31. *
  32. * @ingroup themeable
  33. */
  34. #}
  35. {%
  36. set classes = [
  37. 'cols-' ~ header|length,
  38. sticky ? 'sticky-enabled',
  39. ]
  40. %}
  41. {% if responsive %}
  42. <div class="table-responsive">
  43. {% endif %}
  44. <table{{ attributes.addClass(classes) }}>
  45. {% if caption_needed %}
  46. <caption>
  47. {% if caption %}
  48. {{ caption }}
  49. {% else %}
  50. {{ title }}
  51. {% endif %}
  52. {% if (summary is not empty) or (description is not empty) %}
  53. <details>
  54. {% if summary is not empty %}
  55. <summary>{{ summary }}</summary>
  56. {% endif %}
  57. {% if description is not empty %}
  58. {{ description }}
  59. {% endif %}
  60. </details>
  61. {% endif %}
  62. </caption>
  63. {% endif %}
  64. {% if header %}
  65. <thead>
  66. <tr>
  67. {% for key, column in header %}
  68. {% if column.default_classes %}
  69. {%
  70. set column_classes = [
  71. 'views-field',
  72. 'views-field-' ~ fields[key],
  73. ]
  74. %}
  75. {% endif %}
  76. <th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
  77. {%- if column.wrapper_element -%}
  78. <{{ column.wrapper_element }}>
  79. {%- if column.url -%}
  80. <a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
  81. {%- else -%}
  82. {{ column.content }}{{ column.sort_indicator }}
  83. {%- endif -%}
  84. </{{ column.wrapper_element }}>
  85. {%- else -%}
  86. {%- if column.url -%}
  87. <a href="{{ column.url }}" title="{{ column.title }}">{{ column.content }}{{ column.sort_indicator }}</a>
  88. {%- else -%}
  89. {{- column.content }}{{ column.sort_indicator }}
  90. {%- endif -%}
  91. {%- endif -%}
  92. </th>
  93. {% endfor %}
  94. </tr>
  95. </thead>
  96. {% endif %}
  97. <tbody>
  98. {% for row in rows %}
  99. <tr{{ row.attributes }}>
  100. {% for key, column in row.columns %}
  101. {% if column.default_classes %}
  102. {%
  103. set column_classes = [
  104. 'views-field'
  105. ]
  106. %}
  107. {% for field in column.fields %}
  108. {% set column_classes = column_classes|merge(['views-field-' ~ field]) %}
  109. {% endfor %}
  110. {% endif %}
  111. <td{{ column.attributes.addClass(column_classes) }}>
  112. {%- if column.wrapper_element -%}
  113. <{{ column.wrapper_element }}>
  114. {% for content in column.content %}
  115. {{ content.separator }}{{ content.field_output }}
  116. {% endfor %}
  117. </{{ column.wrapper_element }}>
  118. {%- else -%}
  119. {% for content in column.content %}
  120. {{- content.separator }}{{ content.field_output -}}
  121. {% endfor %}
  122. {%- endif %}
  123. </td>
  124. {% endfor %}
  125. </tr>
  126. {% endfor %}
  127. </tbody>
  128. </table>
  129. {% if responsive %}
  130. </div>
  131. {% endif %}