2

I'm using views to display the fields of nodes. I prefer to use fields because it allows me to use relationships (bring in author profile picture etc.). Adding the Content: Comments field shows the list of comments as well as the comment form for each node. However, when hiding and rewriting the result/and or using the replacement pattern for Content: Comments, the comment form disappears and only the comment list remains.

What methods can I use to display the comment form for each node in a list of nodes view when using fields?

3
  • well for starters whay not make a custom block and attach it to you view as a footer ... then look at the way core comments form works and build the form into that block ? – taggartJ Dec 8 '20 at 5:51
  • If I place a custom block into the view's footer, it will only show one block per view. I'm trying to place the comment form as a field per node. There was a module called Views PHP for Drupal 7, which allowed inserting PHP into the rows, however this was considered bad practice. – ChrisCK Dec 9 '20 at 6:10
  • So... did you try my answer? – No Sssweat Dec 19 '20 at 0:24
2
+25

However, when hiding and rewriting the result/and or using the replacement pattern for Content: Comments, the comment form disappears and only the comment list remains.

It's due to a Views UI bug as I was able to replicate the issue on a fresh install.

A workaround you can do is to do the re-writing via template file rather than via UI.

In your theme's /templates folder add:

views-view-fields--view-name--machine-name.html.twig

and print the view fields there

{{ fields.title.content }} {# title field #}

{{ fields.comment.content }} {# comment field #}

{{ fields.field_name.content }} {# some other field #}

Flush all caches so template gets pickedup.

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.