Skip to main content
  • Guides & Documentation

Knowledgebase

Featured articles, how-to guides and quick tips.

Print the number of field values in Twig - Drupal 8

Sometimes it can be useful to print the number of field values which are present, in a field which supports multiple values.

A possible use case for this would be to display the number of images uploaded in a multi-value File or Media field.

You can render the number of field items using the following Twig syntax for your block or node:

{{ content.field_tabs['#items']|length }}

If, for example, you have 4 images specified in a Media field which supports multiple values, the output of the above syntax would be '4'.