Suppose that in a Twig template, I want to print the first value of a multi-value field, then something else, and finally all other values of the same field. Is there a way to do that?
I know how to get the first value of the field, but I don't know how to exclude that first value from the place where I'm printing all other values.
This is what I tried, but doesn't work:
{# print first field value #}
{{ content.field_foo.0 }}
{# print something else #}
<hr>
{# print remaining field values #}
{{ content.field_foo|without(0) }}
Alternatives for the last line that didn't work either:
{{ content.field_foo|without('0') }}
{{ content.field_foo|without('field_foo.0') }}
Looking at the code in twig_without()
, I would expect {{ content.field_foo|without(0) }}
to work, but instead the entire field disappears.