8 – Count multivalue image field values in views-view-fields.html.twig


Making a presentation template for the gallery. The photo gallery has an image field with multiple values. I need to output the number of gallery photos (in the field_gallery_photo). How do I do this? I tried adding a field with a photo to the view, and all the values are shown in one line. The result is not accurate:

{{ fields.field_gallery_photo.content | length }}

In version 7 I did the following:

  1. added the nid field

  2. redefined the template for it

  3. specified the following in the template:

    $node = node_load($output);
    print sizeof($node->field_gallery_photo('und'));