viewfield-item.html.twig in Viewfield 8.3
Default theme implementation to display a viewfield item.
Instead of overriding the theming for all fields, you can also just override theming for a subset of fields using Theme hook suggestions. For example, here are some theme hook suggestions that can be used for a field_foo field on an article node type:
- viewfield-item--my-view--my-view-display.html.twig
- viewfield-item--my-view-display.html.twig
- viewfield-item--my-view.html.twig
- viewfield-item--field-foo--my-view--my-view-display.html.twig
- viewfield-item--field-foo--my-view-display.html.twig
- viewfield-item--field-foo--my-view.html.twig
- viewfield-item--field-foo--2.html.twig
- viewfield-item--field-foo.html.twig
- viewfield-item.html.twig
Available variables:
- title: The title of this item if visible.
- content: The content of this item.
- attributes: array of HTML attributes populated by modules, intended to be added to the main container tag of this template.
- title_attributes: Same as attributes, except applied to the main title tag that appears in the template.
- title_prefix: Additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
- title_suffix: Additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
- delta: Ordinal specifying the item number in the field.
- entity: The entity object.
- view_mode: View mode; e.g., 'full', 'teaser', etc.
See also
1 theme call to viewfield-item.html.twig
- ViewfieldFormatterDefault::viewElements in src/
Plugin/ Field/ FieldFormatter/ ViewfieldFormatterDefault.php - Builds a renderable array for a field value.
File
templates/viewfield-item.html.twigView source
- {#
- /**
- * @file
- * Default theme implementation to display a viewfield item.
- *
- * Instead of overriding the theming for all fields, you can also just override
- * theming for a subset of fields using
- * @link themeable Theme hook suggestions. @endlink For example,
- * here are some theme hook suggestions that can be used for a field_foo field
- * on an article node type:
- * - viewfield-item--my-view--my-view-display.html.twig
- * - viewfield-item--my-view-display.html.twig
- * - viewfield-item--my-view.html.twig
- * - viewfield-item--field-foo--my-view--my-view-display.html.twig
- * - viewfield-item--field-foo--my-view-display.html.twig
- * - viewfield-item--field-foo--my-view.html.twig
- * - viewfield-item--field-foo--2.html.twig
- * - viewfield-item--field-foo.html.twig
- * - viewfield-item.html.twig
- *
- * Available variables:
- * - title: The title of this item if visible.
- * - content: The content of this item.
- * - attributes: array of HTML attributes populated by modules, intended to
- * be added to the main container tag of this template.
- * - title_attributes: Same as attributes, except applied to the main title
- * tag that appears in the template.
- * - title_prefix: Additional output populated by modules, intended to be
- * displayed in front of the main title tag that appears in the template.
- * - title_suffix: Additional output populated by modules, intended to be
- * displayed after the main title tag that appears in the template.
- * - delta: Ordinal specifying the item number in the field.
- * - entity: The entity object.
- * - view_mode: View mode; e.g., 'full', 'teaser', etc.
- *
- * @see template_preprocess_viewfield_item()
- *
- * @ingroup themeable
- */
- #}
- {%
- set classes = [
- 'field__item',
- 'field__item-label-' ~ label_display,
- ]
- %}
- {%
- set title_classes = [
- 'field__item__label',
- label_display == 'visually_hidden' ? 'visually-hidden',
- ]
- %}
-
- <div{{ attributes.addClass(classes) }}>
- {{ title_prefix }}
- {% if not label_hidden and label %}
- <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
- {% endif %}
- {{ title_suffix }}
- {% block content %}
- {{ content }}
- {% endblock %}
- </div>