0
votes

I am trying to get the comment form with all comments on a custom template article page of drupal. I can get the whole content with {{ page.content }} or get the comments by using {{ node.field_comments }} and make a loop on it (assuming my field comment machine name is field_comments).

But does anyone know I to render the whole comments block with :

  • links to add a comment
  • comments
  • comment form

Thank you very much for your help !

3

3 Answers

0
votes

Try to use the new and refined comment module. It's in the core so all you have to do is enable it. After that just make a comment type, add it to your article and display. That's pretty much it.

0
votes

In template files for a content type (eg node--article.html.twig), you have the 'content' variable available. I use this bit of Twig to render the whole comments block:-

{{ content.comment }}
0
votes

I struggled with this too, but just for the next visitor, I got 2 out of 3 (I didn't want the form on my page)

 - links to add a comment -> {{ content.links }}
 - comments -> {{ content.comment_node_TYPE }}

To get the correct name for content.comment_node_TYPE, visit your Mange fields page for that content type and see what the comment field is called e.g. my "Audio" content type names the field {{ content.comment_node_audio }}

Hope this helps someone in future