annotate core/themes/classy/templates/field/field.html.twig @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 {#
Chris@0 2 /**
Chris@0 3 * @file
Chris@0 4 * Theme override for a field.
Chris@0 5 *
Chris@0 6 * To override output, copy the "field.html.twig" from the templates directory
Chris@0 7 * to your theme's directory and customize it, just like customizing other
Chris@0 8 * Drupal templates such as page.html.twig or node.html.twig.
Chris@0 9 *
Chris@0 10 * Instead of overriding the theming for all fields, you can also just override
Chris@0 11 * theming for a subset of fields using
Chris@0 12 * @link themeable Theme hook suggestions. @endlink For example,
Chris@0 13 * here are some theme hook suggestions that can be used for a field_foo field
Chris@0 14 * on an article node type:
Chris@0 15 * - field--node--field-foo--article.html.twig
Chris@0 16 * - field--node--field-foo.html.twig
Chris@0 17 * - field--node--article.html.twig
Chris@0 18 * - field--field-foo.html.twig
Chris@0 19 * - field--text-with-summary.html.twig
Chris@0 20 * - field.html.twig
Chris@0 21 *
Chris@0 22 * Available variables:
Chris@0 23 * - attributes: HTML attributes for the containing element.
Chris@0 24 * - label_hidden: Whether to show the field label or not.
Chris@0 25 * - title_attributes: HTML attributes for the title.
Chris@0 26 * - label: The label for the field.
Chris@0 27 * - multiple: TRUE if a field can contain multiple items.
Chris@0 28 * - items: List of all the field items. Each item contains:
Chris@0 29 * - attributes: List of HTML attributes for each item.
Chris@0 30 * - content: The field item's content.
Chris@0 31 * - entity_type: The entity type to which the field belongs.
Chris@0 32 * - field_name: The name of the field.
Chris@0 33 * - field_type: The type of the field.
Chris@0 34 * - label_display: The display settings for the label.
Chris@0 35 *
Chris@0 36 *
Chris@0 37 * @see template_preprocess_field()
Chris@0 38 */
Chris@0 39 #}
Chris@0 40 {%
Chris@0 41 set classes = [
Chris@0 42 'field',
Chris@0 43 'field--name-' ~ field_name|clean_class,
Chris@0 44 'field--type-' ~ field_type|clean_class,
Chris@0 45 'field--label-' ~ label_display,
Chris@0 46 ]
Chris@0 47 %}
Chris@0 48 {%
Chris@0 49 set title_classes = [
Chris@0 50 'field__label',
Chris@0 51 label_display == 'visually_hidden' ? 'visually-hidden',
Chris@0 52 ]
Chris@0 53 %}
Chris@0 54
Chris@0 55 {% if label_hidden %}
Chris@0 56 {% if multiple %}
Chris@0 57 <div{{ attributes.addClass(classes, 'field__items') }}>
Chris@0 58 {% for item in items %}
Chris@0 59 <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
Chris@0 60 {% endfor %}
Chris@0 61 </div>
Chris@0 62 {% else %}
Chris@0 63 {% for item in items %}
Chris@0 64 <div{{ attributes.addClass(classes, 'field__item') }}>{{ item.content }}</div>
Chris@0 65 {% endfor %}
Chris@0 66 {% endif %}
Chris@0 67 {% else %}
Chris@0 68 <div{{ attributes.addClass(classes) }}>
Chris@0 69 <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
Chris@0 70 {% if multiple %}
Chris@0 71 <div class="field__items">
Chris@0 72 {% endif %}
Chris@0 73 {% for item in items %}
Chris@0 74 <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
Chris@0 75 {% endfor %}
Chris@0 76 {% if multiple %}
Chris@0 77 </div>
Chris@0 78 {% endif %}
Chris@0 79 </div>
Chris@0 80 {% endif %}