da2c2eebb0527edbcb66646162c4ec89f8960300
[yaffs-website] / vendor / twig / twig / doc / filters / first.rst
1 ``first``
2 =========
3
4 .. versionadded:: 1.12.2
5     The ``first`` filter was added in Twig 1.12.2.
6
7 The ``first`` filter returns the first "element" of a sequence, a mapping, or
8 a string:
9
10 .. code-block:: jinja
11
12     {{ [1, 2, 3, 4]|first }}
13     {# outputs 1 #}
14
15     {{ { a: 1, b: 2, c: 3, d: 4 }|first }}
16     {# outputs 1 #}
17
18     {{ '1234'|first }}
19     {# outputs 1 #}
20
21 .. note::
22
23     It also works with objects implementing the `Traversable`_ interface.
24
25 .. _`Traversable`: https://secure.php.net/manual/en/class.traversable.php