Skip to content
Twig Field Finder
Theme

Number of values in a field

Fill in your field name

Italic values are placeholders: replace them with your own machine names, or let the builder do it.

Reads the entity directly, before field formatters run.

  1. Twig
    {{ node.field_name|length }}

Reads the content render array, after field formatters run.

  1. Twig
    {{ content.field_name['#items']|length }}

Gotcha

Methods like count() are blocked by Drupal’s Twig sandbox; the length filter works because field item lists are countable. For the first item use .0.