field--comment-body.html.twig

Same filename in other branches
  1. 9 core/themes/olivero/templates/field/field--comment-body.html.twig
  2. 11.x core/themes/olivero/templates/field/field--comment-body.html.twig

Olivero's theme override for comment body field.

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.
  • 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 also

template_preprocess_field()

File

core/themes/olivero/templates/field/field--comment-body.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Olivero's theme override for comment body field.
  5. *
  6. * Available variables:
  7. * - attributes: HTML attributes for the containing element.
  8. * - label_hidden: Whether to show the field label or not.
  9. * - title_attributes: HTML attributes for the title.
  10. * - label: The label for the field.
  11. * - multiple: TRUE if a field can contain multiple items.
  12. * - items: List of all the field items. Each item contains:
  13. * - attributes: List of HTML attributes for each item.
  14. * - content: The field item's content.
  15. * - entity_type: The entity type to which the field belongs.
  16. * - field_name: The name of the field.
  17. * - field_type: The type of the field.
  18. * - label_display: The display settings for the label.
  19. *
  20. * @see template_preprocess_field()
  21. */
  22. #}
  23. {%
  24. set classes = [
  25. 'field',
  26. 'field--name-' ~ field_name|clean_class,
  27. 'field--type-' ~ field_type|clean_class,
  28. 'field--label-' ~ label_display,
  29. label_display == 'inline' ? 'clearfix',
  30. ]
  31. %}
  32. {%
  33. set title_classes = [
  34. 'field__label',
  35. label_display == 'visually_hidden' ? 'visually-hidden',
  36. ]
  37. %}
  38. {%
  39. set item_classes = [
  40. 'field__item',
  41. 'comment__text-content',
  42. ]
  43. %}
  44. {% if label_hidden %}
  45. {% if multiple %}
  46. <div{{ attributes.addClass(classes, 'field__items') }}>
  47. {% for item in items %}
  48. <div{{ item.attributes.addClass(item_classes) }}>{{ item.content }}</div>
  49. {% endfor %}
  50. </div>
  51. {% else %}
  52. {% for item in items %}
  53. <div{{ attributes.addClass(classes, item_classes) }}>{{ item.content }}</div>
  54. {% endfor %}
  55. {% endif %}
  56. {% else %}
  57. <div{{ attributes.addClass(classes) }}>
  58. <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
  59. {% if multiple %}
  60. <div class="field__items">
  61. {% endif %}
  62. {% for item in items %}
  63. <div{{ item.attributes.addClass(item_classes) }}>{{ item.content }}</div>
  64. {% endfor %}
  65. {% if multiple %}
  66. </div>
  67. {% endif %}
  68. </div>
  69. {% endif %}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.