Score:0

How to override the output of a views field of type comments

cn flag

My goal is to create a views block that shows the comments of the current node.

I succeeded in creating a views block that includes only the comments field of the node ID from URL.

However, the commenting form is shown below the comments list. I want the form to show above them.

I use the theme olivero, and the normal node display shows the comments form above the comments list.

I see that the node display uses field--comment.html.twig, which allows to change this order in the normal node display. This contains:

{{ attach_library('olivero/comments') }}
<section{{ attributes }}>
  {% if comments and not label_hidden %}
    {{ title_prefix }}
    <h2{{ title_attributes }}>{{ label }}</h2>
    {{ title_suffix }}
  {% endif %}
  
  {% if comment_form %}
    <h2{{ content_attributes }}>{{ 'Add new comment'|t }}</h2>
    {{ comment_form }}
  {% endif %}
  
  {{ comments }}

</section>

However, views does not appear to have a specific comment field display that allows for adjust this order.

The views template available is views-view-field.html.twig What it contains is merely: {{ output -}} If I create a twig template like views-view-field--commentfieldname.html.twig then the output shows the form below the comments list.

If I replace this {{ output -}} with the code in field--comment.html.twig then nothing appears.

Please assist with making the form show above the comments list in views. Thanks

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.