0

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']);
    
2

Your D7 PHP would translate into D8 Twig like this:

{% set node = row._entity %}
{{ node.field_gallery_photo.getvalue | length }}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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