iterable.rst 463B

1234567891011121314151617181920
  1. ``iterable``
  2. ============
  3. .. versionadded:: 1.7
  4. The iterable test was added in Twig 1.7.
  5. ``iterable`` checks if a variable is an array or a traversable object:
  6. .. code-block:: jinja
  7. {# evaluates to true if the foo variable is iterable #}
  8. {% if users is iterable %}
  9. {% for user in users %}
  10. Hello {{ user }}!
  11. {% endfor %}
  12. {% else %}
  13. {# users is probably a string #}
  14. Hello {{ users }}!
  15. {% endif %}