Skip to content

Instantly share code, notes, and snippets.

@yesthatdarya
Last active March 17, 2019 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yesthatdarya/8e56fa99df615f3e207a2a1b909b4e27 to your computer and use it in GitHub Desktop.
Save yesthatdarya/8e56fa99df615f3e207a2a1b909b4e27 to your computer and use it in GitHub Desktop.
A new and improved field template
{%
set classes = [
'field',
'field--name-' ~ field_name|clean_class,
'field--type-' ~ field_type|clean_class,
'field--label-' ~ label_display,
]
%}
{%
set title_classes = [
'field__label',
label_display == 'visually_hidden' ? 'visually-hidden',
]
%}
{% block field %}
<div{{ attributes.addClass(classes) }}>
{% block label %}
{% if label and not label_hidden %}
<div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
{% endif %}
{% endblock %}
{% block content %}
{% if multiple %}
<div class="field__items">
{% block items %}
{% for item in items %}
<div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
{% endfor %}
{% endblock %}
</div>
{% else %}
{{ block('items') }}
{% endif %}
{% endblock %}
</div>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment