3

How can I change the way that comments are displayed on my Drupal 8 page?

I can modify the display of some of the fields at

/admin/structure/comment/manage/comment/display

but this allows for rather limited changes only, e.g. doesn't allow changes to titles and links.

I can create my own view to get a custom layout for the comments, but currently ctools, layout_plugin, and page manager for Drupal 8 are still an alpha release, and therefore I can't attach the view as a panel to my node.

Anyone got any ideas how to solve this? Where could I modify the display of my comments programmatically?

  • I see you have already answered your question and it is a valid solution. However, would you elaborate and say what exactly you would like to modify ? Maybe there will be another way to achieve the same goal, without modifying the templates. – O V Mar 12 '17 at 1:26
  • I wanted to have the title displayed in a different size (h3 rather than h2), and have author name and creation date on separate lines below the title. – PhilippVerpoort Mar 17 '17 at 18:40
4

Take the following template file from your Drupal installation directory

/core/modules/comment/templates/comment.html.twig

and place it in the directory of the theme that you are using in the templates folder, e.g.

/themes/bootstrap/templates/

Then modify that file to change the way that your comments are displayed. You might have to clear the cache to see your changes.

It may be worth creating a sub theme first, so that you don't loose your changes when you install updates for the theme.

  • better use a sub theme, because you'll lose the changes to the bootstrap theme when updating – 4k4 Mar 12 '17 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.