comment.html.twig

Default theme implementation for comments.

Available variables:

  • author: Comment author. Can be a link or plain text.
  • content: The content-related items for the comment display. Use {{ content }} to print them all, or print a subset such as {{ content.field_example }}. Use hide(content.field_example) to temporarily suppress the printing of a given element.
  • created: Formatted date and time for when the comment was created. Preprocess functions can reformat it by calling format_date() with the desired parameters on the 'comment.created' variable.
  • changed: Formatted date and time for when the comment was last changed. Preprocess functions can reformat it by calling format_date() with the desired parameters on the 'comment.changed' variable.
  • new: New comment marker.
  • permalink: Comment permalink.
  • submitted: Submission information created from author and created during template_preprocess_comment().
  • user_picture: The comment author's profile picture.
  • signature: The comment author's signature.
  • status: Comment status. Possible values are: unpublished, published, or preview.
  • title: Comment title, linked to the comment.
  • attributes.class: List of classes that can be used to style contextually through CSS. The default values can be one or more of the following:

    • comment: The current template type; e.g., 'theming hook'.
    • by-anonymous: Comment by an unregistered user.
    • by-node-author: Comment by the author of the parent node.
    • preview: When previewing a new or edited comment.

    The following applies only to viewers who are registered users:

    • unpublished: An unpublished comment visible only to administrators.
    • by-viewer: Comment by the user currently viewing the page.
    • new: New comment since the last visit.
  • 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.
  • content_attributes: List of classes for the styling of the comment content.

These variables are provided to give context about the parent comment (if any):

  • comment_parent: Full parent comment entity (if any).
  • parent_author: Equivalent to author for the parent comment.
  • parent_created: Equivalent to created for the parent comment.
  • parent_changed: Equivalent to changed for the parent comment.
  • parent_title: Equivalent to title for the parent comment.
  • parent_permalink: Equivalent to permalink for the parent comment.
  • parent: A text string of parent comment submission information created from 'parent_author' and 'parent_created' during template_preprocess_comment(). This information is presented to help screen readers follow lengthy discussion threads. You can hide this from sighted users using the class element-invisible.

These two variables are provided for context:

  • comment: Full comment object.
  • node: Node entity the comments are attached to.

See also

template_preprocess()

template_preprocess_comment()

File

drupal/core/modules/comment/templates/comment.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for comments.
  5. *
  6. * Available variables:
  7. * - author: Comment author. Can be a link or plain text.
  8. * - content: The content-related items for the comment display. Use
  9. * {{ content }} to print them all, or print a subset such as
  10. * {{ content.field_example }}. Use hide(content.field_example) to temporarily
  11. * suppress the printing of a given element.
  12. * - created: Formatted date and time for when the comment was created.
  13. * Preprocess functions can reformat it by calling format_date() with the
  14. * desired parameters on the 'comment.created' variable.
  15. * - changed: Formatted date and time for when the comment was last changed.
  16. * Preprocess functions can reformat it by calling format_date() with the
  17. * desired parameters on the 'comment.changed' variable.
  18. * - new: New comment marker.
  19. * - permalink: Comment permalink.
  20. * - submitted: Submission information created from author and created
  21. * during template_preprocess_comment().
  22. * - user_picture: The comment author's profile picture.
  23. * - signature: The comment author's signature.
  24. * - status: Comment status. Possible values are:
  25. * unpublished, published, or preview.
  26. * - title: Comment title, linked to the comment.
  27. * - attributes.class: List of classes that can be used to style contextually
  28. * through CSS. The default values can be one or more of the following:
  29. * - comment: The current template type; e.g., 'theming hook'.
  30. * - by-anonymous: Comment by an unregistered user.
  31. * - by-node-author: Comment by the author of the parent node.
  32. * - preview: When previewing a new or edited comment.
  33. * The following applies only to viewers who are registered users:
  34. * - unpublished: An unpublished comment visible only to administrators.
  35. * - by-viewer: Comment by the user currently viewing the page.
  36. * - new: New comment since the last visit.
  37. * - title_prefix: Additional output populated by modules, intended to be
  38. * displayed in front of the main title tag that appears in the template.
  39. * - title_suffix: Additional output populated by modules, intended to be
  40. * displayed after the main title tag that appears in the template.
  41. * - content_attributes: List of classes for the styling of the comment content.
  42. *
  43. * These variables are provided to give context about the parent comment (if
  44. * any):
  45. * - comment_parent: Full parent comment entity (if any).
  46. * - parent_author: Equivalent to author for the parent comment.
  47. * - parent_created: Equivalent to created for the parent comment.
  48. * - parent_changed: Equivalent to changed for the parent comment.
  49. * - parent_title: Equivalent to title for the parent comment.
  50. * - parent_permalink: Equivalent to permalink for the parent comment.
  51. * - parent: A text string of parent comment submission information created from
  52. * 'parent_author' and 'parent_created' during template_preprocess_comment().
  53. * This information is presented to help screen readers follow lengthy
  54. * discussion threads. You can hide this from sighted users using the class
  55. * element-invisible.
  56. *
  57. * These two variables are provided for context:
  58. * - comment: Full comment object.
  59. * - node: Node entity the comments are attached to.
  60. *
  61. * @see template_preprocess()
  62. * @see template_preprocess_comment()
  63. *
  64. * @ingroup themeable
  65. */
  66. #}
  67. <article{{ attributes }}>
  68. {{ title_prefix }}
  69. {% if new %}
  70. <mark class="new">{{ new }}</mark>
  71. {% endif %}
  72. <h3{{ title_attributes }}>{{ title }}</h3>
  73. {{ title_suffix }}
  74. <footer>
  75. {{ user_picture }}
  76. <p class="submitted">{{ submitted }}</p>
  77. {#
  78. Indicate the semantic relationship between parent and child comments
  79. for accessibility. The list is difficult to navigate in a screen
  80. reader without this information.
  81. #}
  82. {% if parent %}
  83. <p class="parent element-invisible">{{ parent }}</p>
  84. {% endif %}
  85. {{ permalink }}
  86. </footer>
  87. <div{{ content_attributes }}>
  88. {# We hide the links now so that we can render them later. #}
  89. {% hide(content.links) %}
  90. {{ content }}
  91. {% if signature %}
  92. <div class="user-signature">
  93. {{ signature }}
  94. </div>
  95. {% endif %}
  96. </div>
  97. {{ content.links }}
  98. </article>

Related topics