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