mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
21 lines
463 B
ReStructuredText
21 lines
463 B
ReStructuredText
``iterable``
|
|
============
|
|
|
|
.. versionadded:: 1.7
|
|
|
|
The iterable test was added in Twig 1.7.
|
|
|
|
``iterable`` checks if a variable is an array or a traversable object:
|
|
|
|
.. code-block:: twig
|
|
|
|
{# evaluates to true if the foo variable is iterable #}
|
|
{% if users is iterable %}
|
|
{% for user in users %}
|
|
Hello {{ user }}!
|
|
{% endfor %}
|
|
{% else %}
|
|
{# users is probably a string #}
|
|
Hello {{ users }}!
|
|
{% endif %}
|