htools-8.x-1.x-dev/templates/field.html.twig
templates/field.html.twig
{#
/**
* @file
* Theme override for a field based on the @stable field template. See that
* file for full documentation.
*
* field_label supplies one additional variable:
* - label_tag: The label wrapper tag as chosen in the field_label.
*
* This template won't used if your theme overrides field.html.twig. Modify
* your own template to use the label_tag, e.g.:
*
* <{{ label_tag|default('div') }}>
* {{ label }}
* </{{ label_tag|default('div') }}>
*
* @see field_label_preprocess_field()
*/
#}
{%
set classes = [
'field',
'field--name-' ~ field_name|clean_class,
'field--type-' ~ field_type|clean_class,
'field--label-' ~ label_display,
'field--items--show-more--' ~ has_hidden_items,
]
%}
{%
set title_classes = [
'field__label',
label_display == 'visually_hidden' ? 'visually-hidden',
]
%}
{% if label_hidden %}
{% if multiple %}
<div{{ attributes.addClass(classes, 'field__items') }}>
{% for item in items %}
<div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
{% endfor %}
{%- if hidden_items -%}
<details>
<summary>
<span class="detail-summary-closed" >{{ view_more | t }}</span>
<span class="detail-summary-open">{{ view_less | t }}</span>
</summary>
<div>
{%- for item in hidden_items -%}
<div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
{%- endfor -%}
</div>
</details>
{%- endif -%}
</div>
{% else %}
{% for item in items %}
<div{{ attributes.addClass(classes, 'field__item') }}>{{ item.content }}</div>
{% endfor %}
{% endif %}
{% else %}
<div{{ attributes.addClass(classes) }}>
<{{ label_tag|default('div') }}{{ title_attributes.addClass(title_classes) }}>{{ label }}</{{ label_tag|default('div') }}>
{% if multiple %}
<div class="field__items">
{% endif %}
{% for item in items %}
<div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
{% endfor %}
{%- if hidden_items -%}
<details>
<summary>
<span class="detail-summary-closed">{{ view_more | t }}</span>
<span class="detail-summary-open">{{ view_less | t }}</span>
</summary>
<div>
{%- for item in hidden_items -%}
<div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
{%- endfor -%}
</div>
</details>
{%- endif -%}
{% if multiple %}
</div>
{% endif %}
</div>
{% endif %}
