blob: 8d7081a53f1b38136648629f3525570013d172c1 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001``first``
2=========
3
4The ``first`` filter returns the first "element" of a sequence, a mapping, or
5a string:
6
7.. code-block:: twig
8
9 {{ [1, 2, 3, 4]|first }}
10 {# outputs 1 #}
11
12 {{ { a: 1, b: 2, c: 3, d: 4 }|first }}
13 {# outputs 1 #}
14
15 {{ '1234'|first }}
16 {# outputs 1 #}
17
18.. note::
19
20 It also works with objects implementing the `Traversable`_ interface.
21
22.. _`Traversable`: https://secure.php.net/manual/en/class.traversable.php