fieldry-1.0.x-dev/templates/fieldry-wrapper.html.twig
templates/fieldry-wrapper.html.twig
{#
/**
* @file
* Theme twig file for fieldry_wrapper.
*
* Available variables:
* - attributes: HTML attributes for the containing element.
* - label_hidden: Whether to show the field label or not.
* - title_attributes: HTML attributes for the title.
* - label: The label for the field.
* - multiple: TRUE if a field can contain multiple items.
* - content: renderable to be used as the content of the field items and
is meant to be used instead of items. If present this should used
instead of rendering the items individually.
* - items: List of all the field items. Each item contains:
* - attributes: List of HTML attributes for each item.
* - content: The field item's content.
* - entity_type: The entity type to which the field belongs.
* - field_name: The name of the field.
* - field_type: The type of the field.
* - label_display: The display settings for the label.
*
* @see template_preprocess_field()
*/
#}
{{ field_prefix }}
{% if wrapper_tag is not empty %}
{%
set wrapper_classes = [
default_classes ? 'field',
default_classes ? 'field--name-' ~ field_name|clean_class,
default_classes ? 'field--type-' ~ field_type|clean_class,
default_classes ? 'field--label-' ~ label_display,
label_display == 'inline' ? 'clearfix',
]
%}
{%
set title_classes = [
'field__label',
label_display == 'visually_hidden' ? 'visually-hidden',
]
%}
<{{ wrapper_tag }}{{ attributes.addClass(wrapper_classes) }}>
{% if not label_hidden and label %}
<{{ title_tag }}{{ title_attributes.addClass(default_classes ? title_classes) }}>{{ label }}</{{ title_tag }}>
{% endif -%}
{% endif %}
{#
Fieldry wrappers either populate "content" or "items". If content is used
the wrapper wants more control over the output of entire field content.
If "items" is use when field items can be rendered separately and allows
more template control of each item's output.
#}
{% if content %}
{{ content }}
{% else %}
{% if items_wrapper_tag is not empty %}
<{{ items_wrapper_tag }}{{ items_wrapper_attributes.addClass(default_classes ? 'field-items') }}>
{% endif %}
{% if item_tag is not empty %}
{% for item in items %}
<{{ item_tag }}{{ item.attributes.addClass(default_classes ? 'field-item') }}>
{{ item.content }}
</{{ item_tag }}>
{% endfor %}
{% else %}
{#
create items without a wrapper HTML tag - no attributes used when no
item wrapper is being used, only the content gets rendered directly.
#}
{% for item in items %}
{{ item.content }}
{% endfor %}
{% endif %}
{% if items_wrapper_tag is not empty %}
</{{ items_wrapper_tag }}>
{% endif %}
{% endif %}
{% if wrapper_tag is not empty %}
</{{ wrapper_tag }}>
{% endif %}
{{ field_suffix }}
