Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``iterable`` |
2 | ============ | ||||
3 | |||||
4 | ``iterable`` checks if a variable is an array or a traversable object: | ||||
5 | |||||
6 | .. code-block:: twig | ||||
7 | |||||
8 | {# evaluates to true if the foo variable is iterable #} | ||||
9 | {% if users is iterable %} | ||||
10 | {% for user in users %} | ||||
11 | Hello {{ user }}! | ||||
12 | {% endfor %} | ||||
13 | {% else %} | ||||
14 | {# users is probably a string #} | ||||
15 | Hello {{ users }}! | ||||
16 | {% endif %} |