field--comment.html.twig

Same filename in this branch
  1. 11.x core/themes/olivero/templates/field/field--comment.html.twig
  2. 11.x core/themes/stable9/templates/field/field--comment.html.twig
  3. 11.x core/themes/claro/templates/classy/field/field--comment.html.twig
  4. 11.x core/themes/starterkit_theme/templates/field/field--comment.html.twig
  5. 11.x core/modules/comment/templates/field--comment.html.twig
  6. 11.x core/modules/big_pipe/tests/themes/big_pipe_test_theme/templates/field--comment.html.twig
Same filename in other branches
  1. 9 core/profiles/demo_umami/themes/umami/templates/classy/field/field--comment.html.twig
  2. 9 core/themes/olivero/templates/field/field--comment.html.twig
  3. 9 core/themes/stable9/templates/field/field--comment.html.twig
  4. 9 core/themes/seven/templates/classy/field/field--comment.html.twig
  5. 9 core/themes/claro/templates/classy/field/field--comment.html.twig
  6. 9 core/themes/bartik/templates/classy/field/field--comment.html.twig
  7. 9 core/themes/stable/templates/field/field--comment.html.twig
  8. 9 core/themes/starterkit_theme/templates/field/field--comment.html.twig
  9. 9 core/themes/classy/templates/field/field--comment.html.twig
  10. 9 core/modules/comment/templates/field--comment.html.twig
  11. 9 core/modules/big_pipe/tests/themes/big_pipe_test_theme/templates/field--comment.html.twig
  12. 8.9.x core/profiles/demo_umami/themes/umami/templates/classy/field/field--comment.html.twig
  13. 8.9.x core/themes/seven/templates/classy/field/field--comment.html.twig
  14. 8.9.x core/themes/claro/templates/classy/field/field--comment.html.twig
  15. 8.9.x core/themes/bartik/templates/classy/field/field--comment.html.twig
  16. 8.9.x core/themes/stable/templates/field/field--comment.html.twig
  17. 8.9.x core/themes/classy/templates/field/field--comment.html.twig
  18. 8.9.x core/modules/comment/templates/field--comment.html.twig
  19. 8.9.x core/modules/big_pipe/tests/themes/big_pipe_test_theme/templates/field--comment.html.twig
  20. 10 core/profiles/demo_umami/themes/umami/templates/classy/field/field--comment.html.twig
  21. 10 core/themes/olivero/templates/field/field--comment.html.twig
  22. 10 core/themes/stable9/templates/field/field--comment.html.twig
  23. 10 core/themes/claro/templates/classy/field/field--comment.html.twig
  24. 10 core/themes/starterkit_theme/templates/field/field--comment.html.twig
  25. 10 core/modules/comment/templates/field--comment.html.twig
  26. 10 core/modules/big_pipe/tests/themes/big_pipe_test_theme/templates/field--comment.html.twig

Theme override for comment fields.

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.
  • 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 title output populated by modules, intended to be displayed after the main title tag that appears in the template.
  • comments: List of comments rendered through comment.html.twig.
  • comment_form: The 'Add new comment' form.
  • comment_display_mode: Is the comments are threaded.
  • comment_type: The comment type bundle ID for the comment field.
  • 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()

comment_preprocess_field()

File

core/profiles/demo_umami/themes/umami/templates/classy/field/field--comment.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for comment fields.
  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. * - title_prefix: Additional output populated by modules, intended to be
  12. * displayed in front of the main title tag that appears in the template.
  13. * - title_suffix: Additional title output populated by modules, intended to
  14. * be displayed after the main title tag that appears in the template.
  15. * - comments: List of comments rendered through comment.html.twig.
  16. * - comment_form: The 'Add new comment' form.
  17. * - comment_display_mode: Is the comments are threaded.
  18. * - comment_type: The comment type bundle ID for the comment field.
  19. * - entity_type: The entity type to which the field belongs.
  20. * - field_name: The name of the field.
  21. * - field_type: The type of the field.
  22. * - label_display: The display settings for the label.
  23. *
  24. * @see template_preprocess_field()
  25. * @see comment_preprocess_field()
  26. */
  27. #}
  28. {%
  29. set classes = [
  30. 'field',
  31. 'field--name-' ~ field_name|clean_class,
  32. 'field--type-' ~ field_type|clean_class,
  33. 'field--label-' ~ label_display,
  34. 'comment-wrapper',
  35. ]
  36. %}
  37. {%
  38. set title_classes = [
  39. 'title',
  40. label_display == 'visually_hidden' ? 'visually-hidden',
  41. ]
  42. %}
  43. <section{{ attributes.addClass(classes) }}>
  44. {% if comments and not label_hidden %}
  45. {{ title_prefix }}
  46. <h2{{ title_attributes.addClass(title_classes) }}>{{ label }}</h2>
  47. {{ title_suffix }}
  48. {% endif %}
  49. {{ comments }}
  50. {% if comment_form %}
  51. <h2 class="title comment-form__title">{{ 'Add new comment'|t }}</h2>
  52. {{ comment_form }}
  53. {% endif %}
  54. </section>

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