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