{# Default output for fields. This file is contains the 'sub_fields' Twig block tag. The 'sub_fields' Twig block is split into two parts: - The first section initializes the variables and settings, both from the ContentType definitions as well as passed in variables. - The last section is where the actual looping is done, and the relevant {{ block() }} function is called, for the 'ContentType fields', 'repeater fields' and 'template fields' in turn. Read the relevant section in the documentation on usage of this functionality: https://docs.bolt.cm/templating For more information on using blocks, see the Twig documentation at: - https://twig.sensiolabs.org/doc/1.x/tags/block.html - https://twig.sensiolabs.org/doc/1.x/functions/block.html #} {% use 'partials/_sub_field_blocks.twig' %} {% block sub_fields %} {# SECTION 1: INITIALIZATION #} {%- spaceless %} {# Set up the array of fieldnames that should be iterated. We do this by looping over _all_ the fields, and skipping those in the 'omittedkeys' array. #} {% set omittedkeys = [ 'id', 'slug', 'datecreated', 'datechanged', 'datepublish', 'datedepublish', 'username', 'status', 'ownerid', 'templatefields' ] %} {# Skip over the fields that are used in the slug, unless explicitly told not to, using the `skip_uses` parameter. #} {% if (record.contenttype.fields.slug.uses|default(null) is iterable) and skip_uses|default(true) %} {% set omittedkeys = omittedkeys|merge(record.contenttype.fields.slug.uses) %} {% endif %} {# We also skip over the fields that are explicitly excluded. #} {% if exclude|default is iterable %} {% set omittedkeys = omittedkeys|merge(exclude) %} {% endif %} {% endspaceless -%} {# SECTION 2: LOOPING AND ITERATION - The actual looping is done here. #} {% for key, value in record.values if (key not in omittedkeys) %} {# Is the field allowed to contain Twig functions #} {% set allowtwig = record.contenttype.fields[key].allowtwig|default(false) %} {# Fields that are considered 'common': 'html', 'markdown', 'textarea', 'text', 'image', 'video' and 'imagelist' #} {% if common|default(true) and (key not in exclude|default([])) %} {% set fieldtype = record.fieldtype(key) %} {% set value = record.get(key) %} {{ block('common_fields') }} {% endif %} {# The rest of the built-in fieldtypes #} {% if extended|default(false) and (key not in exclude|default([])) %} {% set fieldtype = record.fieldtype(key) %} {{ block('extended_fields') }} {% endif %} {# Finally, the repeaters and blocks #} {% if (repeaters|default(false) == true and record.fieldtype(key) == "repeater") or (blocks|default(false) == true and record.fieldtype(key) == "block") %} {# Get the current route from either '_internal_route' or '_route' #} {% set route = global.request.get('_internal_route', global.request.get('_route')) %} {% if route != "preview" %} {% for repeater in value %} {% for key, repeaterfield in repeater %} {% set fieldtype = repeaterfield.fieldtype() %} {% set value = repeaterfield.value() %} {{ block('common_fields') }} {{ block('extended_fields') }} {% endfor %} {% endfor %} {% else %} {# @deprecated `blocks()` does not work correctly when _previewing_ repeater/block fields. This will be fixed properly for Bolt 4, but for now we just output a notice, and prevent crashes. See also: https://github.com/bolt/bolt/issues/6605 #}

Unfortunately, Repeater fields and Block Fields do not work correctly with the generic block() function, when using the "Preview" button.
To view these fields, please save the record, and view the page normally.

{% endif %} {% endif %} {% endfor %} {# We do the same for the templatefields, if set and not empty. #} {% set templatefields = record.values.templatefields.values|default() %} {% if templatefields is not empty %} {# Note: This needs to be expanded upon!! For better detection the 'virtual' contenttype for the templatefields should know about the types of fields. #} {% set templatefields_field_types = attribute(record.contenttype.templatefields|first, 'fields') %} {% for key, value in templatefields if (key not in omittedkeys) %} {% set fieldtype = attribute(attribute(templatefields_field_types, key), 'type') %} {{ block('common_fields') }} {{ block('extended_fields') }} {% endfor %} {% endif %} {% endblock sub_fields %}