Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``length`` |
| 2 | ========== |
| 3 | |
| 4 | The ``length`` filter returns the number of items of a sequence or mapping, or |
| 5 | the length of a string. |
| 6 | |
| 7 | For objects that implement the ``Countable`` interface, ``length`` will use the |
| 8 | return value of the ``count()`` method. |
| 9 | |
| 10 | For objects that implement the ``__toString()`` magic method (and not ``Countable``), |
| 11 | it will return the length of the string provided by that method. |
| 12 | |
| 13 | For objects that implement the ``Traversable`` interface, ``length`` will use the return value of the ``iterator_count()`` method. |
| 14 | |
| 15 | .. code-block:: twig |
| 16 | |
| 17 | {% if users|length > 10 %} |
| 18 | ... |
| 19 | {% endif %} |