{% include "formMacros.html" %} {# Called for you by schemaFields when a group is encountered. #} {% macro schemaOpenGroup(fields, group, active) %}
{% endmacro %} {# Called for you by schemaFields when a group ends. #} {% macro schemaCloseGroup() %}
{% endmacro %} {# Output all the fields in a schema. Second argument is optional, contains options. #} {# NOTE: all of the options below may have surprising results if used #} {# in a schema with groups (aka tabs). If you are using tabs we #} {# suggest you specify a template name for any custom fields rather #} {# than attempting to template them inline with multiple calls to #} {# schemaFields. #} {# If "from" is set, start with that field. If "after" is set, start after it. #} {# If "to" is set, end with that field. If "before" is set, end just before it. #} {# You can use "from", "to", "after" and "before" to output a portion of the schema fields #} {# in order, automatically, then output one in a customized way, then resume #} {# outputting the rest automatically. #} {# You can also output specific fields by specifying only: [ 'field1', 'field2' ... ] #} {# or exclude specific fields by specifying except: [ 'field1', 'field2' ... ]. #} {# Fields are always output in the order specified at configuration time. #} {# Any field types not known to this macro are skipped, without error. #} {% macro schemaFields(fields, options = { from: false, to: false, except: [], only: false }) %} {% set groups = aposFilter(fields, 'type', 'group') %} {% set firstGroupReached = false %} {% set fromFound = false %} {% set toFound = false %} {% for field in fields %} {% if (not (options.from or options.after)) or (field.name == options.from) %} {% set fromFound = true %} {% endif %} {% if (field.name == options.before) %} {% set toFound = true %} {% endif %} {% set found = fromFound and (not toFound) %} {% set notExcepted = (not aposContains(options.except, field.name)) %} {% set allowed = (not options.only) or aposContains(options.only, field.name) %} {% set notContextual = (not field.contextual) %} {% if (found and notExcepted and allowed and notContextual) %} {% if field.group and (field.group != lastGroup) %} {% if lastGroup %} {{ schemaCloseGroup() }} {% set activeGroup = false %} {% else %} {% set activeGroup = true %} {# First grouped control encountered, open the tabs div #}
{% for group in groups %}
{{ group.label }}
{% endfor %}
{% endif %} {{ schemaOpenGroup(fields, field.group, activeGroup) }} {% set lastGroup = field.group %} {% endif %} {# Invokes standard templates for each type in apostrophe-schemas/templates/views, or custom renderers if supplied for the field's type or that individual field #} {{ aposSchemaField(field) }} {% if field.help %}

{{ field.help | e }}

{% endif %} {% endif %} {% if (field.name == options.to) %} {% set toFound = true %} {% endif %} {% if (field.name == options.after) %} {% set fromFound = true %} {% endif %} {% endfor %} {# Nunjucks won't let us just test lastGroup from here due to #} {# scoping issues https://github.com/mozilla/nunjucks/issues/166 #} {% if aposFilterNonempty(fields, 'group').length %} {{ schemaCloseGroup() }}
{% endif %} {% endmacro %} {% macro schemaArray(name, label, schema) %}
{# #} {# Cannot be inside the sortable div #} Add {{ __(label) | e }}
{# #}{# #}
{{ schemaFields(schema) }}
{% endmacro %}