Skip to content

Commit

Permalink
Merge pull request #619 from bolt/hotfix/fields
Browse files Browse the repository at this point in the history
Simplify "fields" a bit.
  • Loading branch information
bobdenotter committed Sep 11, 2019
2 parents 481348b + f87c5a3 commit 0aa9157
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
2 changes: 1 addition & 1 deletion public/theme/skeleton/record.twig
Expand Up @@ -16,7 +16,7 @@
{# Output all fields, in the order as defined in the content type.
To change the generated html and configure the options, see:
https://docs.bolt.cm/templating #}
{% with { 'record': record, 'common': true, 'extended': true, 'repeaters': true, 'blocks': true, 'exclude': [record|image.fieldname] } %}
{% with { 'record': record, 'exclude': [record|image.fieldname|default()] } %}
{{ block('sub_fields', 'partials/_sub_fields.twig') }}
{% endwith %}

Expand Down
19 changes: 2 additions & 17 deletions templates/helpers/_fields.twig
Expand Up @@ -7,8 +7,7 @@
- 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', 'block fields' and 'template fields' in turn.
{{ block() }} function is called, for the 'ContentType fields' in turn.
Read the relevant section in the documentation on usage of this
functionality: https://docs.bolt.cm/templating
Expand All @@ -22,6 +21,7 @@
{% block sub_fields %}
{# SECTION 1: INITIALIZATION #}
{%- apply 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',
Expand Down Expand Up @@ -61,19 +61,4 @@

{% endfor %}

{# We do the same for the templatefields, if set and not empty. #}
{% if record.hasField('templateFields') %}
{# Note: This needs to be expanded upon!! For better detection the 'virtual'
content type for the templatefields should know about the types of fields. #}
{% set templatefields_field_types = attribute(record.contentType.templatefields.first, 'fields') %}

{% for key, field in record.templateFields|filter(key => key not in omittedkeys) %}

{% set type = attribute(attribute(templatefields_field_types, key), 'type') %}
{{ block('common_fields') }}
{{ block('extended_fields') }}

{% endfor %}

{% endif %}
{% endblock sub_fields %}

0 comments on commit 0aa9157

Please sign in to comment.