comment.html.twig

Bartik's 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/themes/bartik/templates/comment.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Bartik's 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 class="{{ attributes.class }} clearfix"{{ attributes }} role="article">
  68. <header class="comment-header">
  69. <div class="attribution">
  70. {{ user_picture }}
  71. <div class="submitted">
  72. <p class="commenter-name">
  73. {{ author }}
  74. </p>
  75. <p class="comment-time">
  76. {{ created }}
  77. </p>
  78. <p class="comment-permalink">
  79. {{ permalink }}
  80. </p>
  81. {#
  82. // Indicate the semantic relationship between parent and child comments
  83. // for accessibility. The list is difficult to navigate in a screen
  84. // reader without this information.
  85. #}
  86. {% if parent %}
  87. <p class="comment-parent element-invisible">
  88. {{ parent }}
  89. </p>
  90. {% endif %}
  91. </div>
  92. </div> <!-- /.attribution -->
  93. <div class="comment-text">
  94. <div class="comment-arrow"></div>
  95. {% if new %}
  96. <span class="new">{{ new }}</span>
  97. {% endif %}
  98. {{ title_prefix }}
  99. <h3{{ title_attributes }}>{{ title }}</h3>
  100. {{ title_suffix }}
  101. </div> <!-- /.comment-text -->
  102. </header> <!-- /.comment-header -->
  103. <div{{ content_attributes }}>
  104. {# We hide the links now so that we can render them later. #}
  105. {% hide(content.links) %}
  106. {{ content }}
  107. </div> <!-- /.content -->
  108. <footer class="comment-footer">
  109. {% if signature %}
  110. <div class="user-signature clearfix">
  111. {{ signature }}
  112. </div>
  113. {% endif %}
  114. <nav>
  115. {{ content.links }}
  116. </nav>
  117. </footer> <!-- /.comment-footer -->
  118. </article>

Related topics