Score:0

How can I print view/edit/comment links?

tr flag

I have a view that uses the "View content," "edit content," and "view comments" fields. I can't figure out how to print these in a custom twig template.

I've tried:

{{ fields.comments_link.content }}
{{ fields.comments_link }}
{{ comments_link }}

Similar attempts to print the view and edit links didn't work either. Other fields print fine. Can someone point me in the right direction, or do I just need to call the NID into the view and print that into a link?

leymannx avatar
ne flag
What View? What template? Install Twig Debug and then put `{{ dd() }}` to see what's available. When you added these fields to the view they should already be there though.
tr flag
My issue has resolved itself. I've updated the post.
Score:1
pw flag

Add "view content" & "edit content" link in view as follow

enter image description here

Then put views-view-table--articles.html.twig file in your theme's template directory and get fields as follow.

<div class="example-template">

{% for row in rows %}
  {% set titletxt = '' %}
  {% set viewnod = '' %}
  {% set editnode = '' %}
    {% for key, column in row.columns %}
       
      {% for field in column.fields %}                                    
        
        {% for content in column.content %}
          
          {% if field == 'title' %}
             {% set titletxt = content.field_output %}
          {% endif %}

          {% if field == 'view-node' %}
             {% set viewnod = content.field_output %}
          {% endif %}              

          {% if field == 'edit-node' %}
             {% set editnode = content.field_output %}
          {% endif %}

        {% endfor %}
         
      {% endfor %}
      
    {% endfor %}
    
    <div>
      <h3>
        {{titletxt}}
      </h3>
      <div>
        {{viewnod}}
      </div>
      <div>
        {{editnode}}
      </div>
    </div>
  
{% endfor %}

Please have a look, this might help you. Thanks

tr flag
Strangely enough, it now prints with {{ field.view_node.content }}. I'm not sure why it wasn't printing. But my problem seems to have resolved itself. Thanks for this answer. It may help someone else.
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.