|
| 1 | +{# |
| 2 | +/** |
| 3 | + * @file |
| 4 | + * Theme override for a field. |
| 5 | + * |
| 6 | + * To override output, copy the "field.html.twig" from the templates directory |
| 7 | + * to your theme's directory and customize it, just like customizing other |
| 8 | + * Drupal templates such as page.html.twig or node.html.twig. |
| 9 | + * |
| 10 | + * Instead of overriding the theming for all fields, you can also just override |
| 11 | + * theming for a subset of fields using |
| 12 | + * @link themeable Theme hook suggestions. @endlink For example, |
| 13 | + * here are some theme hook suggestions that can be used for a field_foo field |
| 14 | + * on an article node type: |
| 15 | + * - field--node--field-foo--article.html.twig |
| 16 | + * - field--node--field-foo.html.twig |
| 17 | + * - field--node--article.html.twig |
| 18 | + * - field--field-foo.html.twig |
| 19 | + * - field--text-with-summary.html.twig |
| 20 | + * - field.html.twig |
| 21 | + * |
| 22 | + * Available variables: |
| 23 | + * - attributes: HTML attributes for the containing element. |
| 24 | + * - label_hidden: Whether to show the field label or not. |
| 25 | + * - title_attributes: HTML attributes for the title. |
| 26 | + * - label: The label for the field. |
| 27 | + * - multiple: TRUE if a field can contain multiple items. |
| 28 | + * - items: List of all the field items. Each item contains: |
| 29 | + * - attributes: List of HTML attributes for each item. |
| 30 | + * - content: The field item's content. |
| 31 | + * - entity_type: The entity type to which the field belongs. |
| 32 | + * - field_name: The name of the field. |
| 33 | + * - field_type: The type of the field. |
| 34 | + * - label_display: The display settings for the label. |
| 35 | + * |
| 36 | + * |
| 37 | + * @see template_preprocess_field() |
| 38 | + */ |
| 39 | +#} |
| 40 | + |
| 41 | +{% |
| 42 | + set classes = [ |
| 43 | + 'field', |
| 44 | + 'fieldName-' ~ field_name|clean_class, |
| 45 | + 'fieldType-' ~ field_type|clean_class, |
| 46 | + 'layout-fieldLabel-' ~ label_display|clean_class, |
| 47 | + ] |
| 48 | +%} |
| 49 | +{% |
| 50 | + set title_classes = [ |
| 51 | + 'field-label', |
| 52 | + label_display == 'visually_hidden' ? 'visuallyHidden', |
| 53 | + ] |
| 54 | +%} |
| 55 | + |
| 56 | + |
| 57 | +<span id="qaTop"></span> |
| 58 | +<div class="paragraphQA-questions-wrapper"> |
| 59 | +<div class="paragraphQA-content"> |
| 60 | + <ol class="paragraphQA-questions"> |
| 61 | + {% if multiple %} |
| 62 | + <li{{ attributes.addClass(classes, 'field-items') }}> |
| 63 | + {% for item in items %} |
| 64 | + {# Test for paragraph, and if present, add paragraph name to class list. #} |
| 65 | + {% if item.content['#paragraph'].bundle|trim is not empty %} |
| 66 | + <li{{ item.attributes.addClass('field-item', 'paragraphItem-'~ item.content['#paragraph'].bundle|replace({'_': '-'})) }}><a href="#question-{{loop.index}}"> {{ item.content['#paragraph'].field_question.value }}</a></li> |
| 67 | + {% else %} |
| 68 | + <li{{ item.attributes.addClass('field-item') }}><a href="#question-{{loop.index}}"> {{ item.content['#paragraph'].field_question.value }}</a></li> |
| 69 | + {% endif %} |
| 70 | + {% endfor %} |
| 71 | + </li> |
| 72 | + {% else %} |
| 73 | + {% for item in items %} |
| 74 | + {# Test for paragraph, and if present, add paragraph name to class list. #} |
| 75 | + {% if item.content['#paragraph'].bundle|trim is not empty %} |
| 76 | + <li{{ attributes.addClass(classes, 'field-item', 'paragraphItem-'~ item.content['#paragraph'].bundle|replace({'_': '-'})) }}><a href="#question-{{loop.index}}"> {{ item.content }}</a></ili> |
| 77 | + {% else %} |
| 78 | + <li{{ attributes.addClass(classes, 'field-item') }}>{{ item.content }}</li> |
| 79 | + {% endif %} |
| 80 | + {% endfor %} |
| 81 | + {% endif %} |
| 82 | + </ol> |
| 83 | +</div> |
| 84 | +</div> |
| 85 | + |
| 86 | +{% if label_hidden %} |
| 87 | + {% if multiple %} |
| 88 | + <div class="paragraphQA-answers-wrapper"> |
| 89 | + <div class="paragraphQA-content"> |
| 90 | + <div{{ attributes.addClass(classes, 'field-items') }}> |
| 91 | + <ol class="paragraphQA-answers"> |
| 92 | + {% for item in items %} |
| 93 | + {# Test for paragraph, and if present, add paragraph name to class list. #} |
| 94 | + <li> |
| 95 | + {% if item.content['#paragraph'].bundle|trim is not empty %} |
| 96 | + <div id="question-{{loop.index}}" {{ item.attributes.addClass('field-item', 'paragraphItem-'~ item.content['#paragraph'].bundle|replace({'_': '-'})) }}>{{ item.content }}</div> |
| 97 | + {% else %} |
| 98 | + <div id="question-{{loop.index}}" {{ item.attributes.addClass('field-item') }}>{{ item.content }}</div> |
| 99 | + {% endif %} |
| 100 | + </li> |
| 101 | + {% endfor %} |
| 102 | + </div> |
| 103 | + {% else %} |
| 104 | + {% for item in items %} |
| 105 | + <li> |
| 106 | + {# Test for paragraph, and if present, add paragraph name to class list. #} |
| 107 | + {% if item.content['#paragraph'].bundle|trim is not empty %} |
| 108 | + <div id="question-{{loop.index}}" {{ attributes.addClass(classes, 'field-item', 'paragraphItem-'~ item.content['#paragraph'].bundle|replace({'_': '-'})) }}>{{ item.content }}</div> |
| 109 | + {% else %} |
| 110 | + <div id="question-{{loop.index}}" {{ attributes.addClass(classes, 'field-item') }}>{{ item.content }}</div> |
| 111 | + {% endif %} |
| 112 | + </li> |
| 113 | + {% endfor %} |
| 114 | + {% endif %} |
| 115 | +{% else %} |
| 116 | + <div{{ attributes.addClass(classes) }}> |
| 117 | + <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div> |
| 118 | + {% if multiple %} |
| 119 | + <div class="field-items"> |
| 120 | + {% endif %} |
| 121 | + {% for item in items %} |
| 122 | + <li> |
| 123 | +{# Test for paragraph, and if present, add paragraph name to class list. #} |
| 124 | + {% if item.content['#paragraph'].bundle|trim is not empty %} |
| 125 | + <div id="question-{{loop.index}}" {{ item.attributes.addClass('field-item', 'paragraphItem-'~ item.content['#paragraph'].bundle|replace({'_': '-'})) }}>{{ item.content }}</div> |
| 126 | + {% else %} |
| 127 | + <div id="question-{{loop.index}}" {{ item.attributes.addClass('field-item') }}>{{ item.content }}</div> |
| 128 | + {% endif %} |
| 129 | + </li> |
| 130 | + {% endfor %} |
| 131 | + {% if multiple %} |
| 132 | + </div> |
| 133 | + {% endif %} |
| 134 | + </div> |
| 135 | +</ol> |
| 136 | +</div> |
| 137 | +</div> |
| 138 | +{% endif %} |
0 commit comments