{% apply spaceless %} {# Parameters: - "simple" (boolean) (default: false) - "sortable" (boolean) (default: false) - "zebra" (boolean) (default: false)) - "headers" (array) (default: []): format: [ { "label" (string or array of string) "colspan" (string) (default: ''), "data-ecl-table-header-group" (string) (default: ''), }, ... ] - "rows" (array) (default: {}): format: [ [ "extra_classes": (string) (default: ''), { "label" (string or array of string) "data-ecl-table-header" (string) (default: ''), "group" (bool) (default: false), }, ... ], ... ] - "extra_classes" (string) (default: '') - "extra_attributes" (array) (default: []): format: [ { "name" (string) (default: ''), "value" (optional) (string) }, ... ], #} {# Internal properties #} {% set _css_class = 'ecl-table' %} {% set _extra_attributes = '' %} {% set _simple_css_class = 'ecl-table--simple' %} {% set _zebra_css_class = 'ecl-table--zebra' %} {% set _head_css_class = 'ecl-table__head' %} {% set _header_css_class = 'ecl-table__header' %} {% set _body_css_class = 'ecl-table__body' %} {% set _cell_header_group_class = 'ecl-table__cell--group' %} {% set _row_css_class = 'ecl-table__row' %} {% set _headers = headers|default([]) %} {% set _simple = simple|default(false) %} {% set _sortable = sortable|default(false) %} {% set _rows = rows|default([]) %} {% set _zebra = zebra|default(false) %} {# Internal logic - Process properties #} {% if extra_classes is defined and extra_classes is not empty %} {% set _css_class = _css_class ~ ' ' ~ extra_classes %} {% endif %} {% if _sortable %} {% set extra_attributes = extra_attributes|default([])|merge([ { name: 'data-ecl-table' }, { name: 'data-ecl-auto-init', value: 'Table' } ]) %} {% endif %} {% if _simple %} {% set _css_class = _css_class ~ ' ' ~ _simple_css_class %} {% endif %} {% if _zebra %} {% set _css_class = _css_class ~ ' ' ~ _zebra_css_class %} {% endif %} {% if extra_attributes is defined and extra_attributes is not empty and extra_attributes is iterable %} {% for attr in extra_attributes %} {% if attr.value is defined %} {% set _extra_attributes = _extra_attributes ~ ' ' ~ attr.name|e('html_attr') ~ '="' ~ attr.value|e('html_attr') ~ '"' %} {% else %} {% set _extra_attributes = _extra_attributes ~ ' ' ~ attr.name|e('html_attr') %} {% endif %} {% endfor %} {% endif %} {# Print the result #}
{% for header in _headers %} {% for cell in header %} {% set _heading_attribute = '' %} {% if cell.colspan is not empty %} {% set _heading_attribute = cell.colspan is not empty ? 'colspan="' ~ cell.colspan|e('html_attr') ~ '"' : '' %} {% else %} {% if cell.label is not empty and _sortable %} {% set _heading_attribute = 'data-ecl-table-sort-toggle' %} {% endif %} {% endif %} {% endfor %} {% endfor %} {% for row in _rows %} {% set _row_css_class = 'ecl-table__row' %} {% if row.extra_classes is defined and row.extra_classes is not empty %} {% set _row_css_class = _row_css_class ~ ' ' ~ row.extra_classes %} {% endif %} {% for cell in row.cells %} {% set _cell_css_class = 'ecl-table__cell' %} {% set _cell_attribute = cell['data-ecl-table-header'] is not empty ? 'data-ecl-table-header="' ~ cell['data-ecl-table-header']|e('html_attr') ~ '"' : '' %} {% if cell.group %} {% if cell['data-ecl-table-header-group'] is defined and cell['data-ecl-table-header-group'] is not empty %} {% set _cell_attribute = _cell_attribute ~ ' data-ecl-table-header-group="' ~ cell['data-ecl-table-header-group']|e('html_attr') ~ '"' %} {% endif %} {% set _cell_css_class = _cell_css_class ~ ' ' ~ _cell_header_group_class %} {% endif %} {% endfor %} {% endfor %}
{{ cell.label }}
{{ cell.label }}
{% endapply %}