How to print in twig a Flag Link field I have a views-view-unformatted.html.twig template working fine where I can print fields from a view of nodes.

Example: having i = 3, print row number 3 title

{{ rows[i]['content']['#row']._entity.title.0.value }}


This view has also a working relationship with flag. I see it working in the view preview.

How can I print the flag link inside views-view-unformatted.html.twig?
Not being able to find better solution nor documetation, I built this working hack:


add a fake text field entity. IE: for articles: http://yoursite/admin/structure/types/manage/article/fields  > Add field > Add text plain field
hook the view in a custom module:

function MYMODULE_views_pre_render(ViewExecutable &amp;$view){
  if( $view-&gt;id() == 'VIEWID' ){
    foreach($view-&gt;result as $r) {
    // from https://www.drupal.org/comment/reply/295383/12504094
    $node = $r-&gt;_entity;
    $flag_link = [
      '#lazy_builder' =&gt; ['flag.link_builder:build', [
      $node-&gt;getEntityTypeId(),
      $node-&gt;id(),
      'FLAG',
    ]],
    '#create_placeholder' =&gt; TRUE,
  ];
  $flag_link = render($flag_link);
  $r-&gt;_entity-&gt;set('field_fake_flag_field', $flag_link); //.
    }
  }
}

print (finally) your flag link in the twig template:

{{ rows[i]['content']['#row']._entity.field_fake_flag_field.0.value }}


Twig is cool. It takes a while, sometimes.