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.

What methods can I use to display the comment form for each node?

2
  • 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, 2020 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, 2020 at 6:10

1 Answer 1

3
+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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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