{%- set static = (static is defined ? static : false) %} {%- set staticRows = static ? true : (staticRows is defined ? staticRows : false) %} {%- set cols = (cols is defined ? cols : []) %} {%- set rows = (rows is defined ? rows : []) -%} {% for col in cols %} {% endfor %} {% if not staticRows %} {% endif %} {% for rowId, row in rows %} {% for colId, col in cols %} {% set value = row[colId] is defined ? (row[colId].value is defined ? row[colId].value : row[colId]) : null %} {% if col.type == 'heading' %} {% else %} {% set hasErrors = row[colId].hasErrors ?? false %} {% set cellName = name~'['~rowId~']['~colId~']' %} {% set textual = (col.type in ['singleline','multiline','number']) %} {% endif %} {% endfor %} {% if not staticRows %} {% endif %} {% endfor %}
{%- if col.heading is defined and col.heading %}{{ col.heading }}{% else %} {% endif %} {%- if col.info is defined -%} {{ col.info|md|raw }} {%- endif -%}
{{ value|raw }} {%- switch col.type -%} {% case 'select' -%} {% include "_includes/forms/select" with { class: 'small', name: cellName, options: col.options, value: value, disabled: static } only %} {%- case 'checkbox' -%} {%- case 'lightswitch' -%} {% include "_includes/forms/lightswitch" with { name: cellName, on: value, value: col.value ?? 1, small: true, disabled: static } only %} {%- default -%} {%- endswitch -%}
{% if not staticRows %}
{{ addRowLabel is defined ? addRowLabel : "Add a row"|t('app') }}
{% endif %} {% if not static and (initJs is not defined or initJs) %} {% js %} new Craft.EditableTable( "{{ id | namespaceInputId | e('js') }}", "{{ name | namespaceInputName | e('js') }}", {{ cols|json_encode|raw }}); {% endjs %} {% endif %}