{# Adds a block of custom form fields. extras - The fields to add. errors - A dict of errors for the fields. limit - The total number of fields that should be output. Example: {% snippet 'snippets/custom_form_fields.html', extras=data.extras, errors=errors, limit=3 %} #} {% import "macros/form.html" as form %}
{% set custom_extras = ['licenseAttributionByText', 'temporal_start', 'temporal_end', 'issued', 'spatial_uri', 'groups'] %} {% for extra in extras %} {% if extra.key not in custom_extras %} {% set prefix = 'extras__%d__' % (loop.index0 + (custom_extras|count)) %} {{ form.custom( names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'), id='field-extras-%d' % loop.index0, label=_('Custom Field'), values=(extra.key, extra.value, extra.deleted), error=errors[prefix ~ 'key'] or errors[prefix ~ 'value'] ) }} {% endif %} {% endfor %} {# Add a max of 3 empty columns #} {% set total_extras = extras|count %} {% if total_extras <= (custom_extras|count) %}{% set total_extras = (custom_extras|count) %}{% endif %} {% set empty_extras = (limit or 3) - total_extras %} {% if empty_extras <= 0 %}{% set empty_extras = 1 %}{% endif %} {% for extra in range(total_extras, total_extras + empty_extras) %} {% set index = loop.index0 + total_extras %} {% set prefix = 'extras__%d__' % index %} {{ form.custom( names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'), id='field-extras-%d' % index, label=_('Custom Field'), values=(extra.key, extra.value, extra.deleted), error=errors[prefix ~ 'key'] or errors[prefix ~ 'value'] ) }} {% endfor %}