Twig

灵活、快速且安全的
PHP 模板引擎

a Symfony Product
文档 测试 iterable
您正在阅读 Twig 3.x 的文档。切换到 Twig 1.x, 2.x 的文档。

问题 & 反馈

许可

Twig 文档 基于新 BSD 许可 授权。

iterable

iterable 检查变量是否为数组或可遍历对象

1
2
3
4
5
6
7
8
9
{# evaluates to true if the users variable is iterable #}
{% if users is iterable %}
    {% for user in users %}
        Hello {{ user }}!
    {% endfor %}
{% else %}
    {# users is probably a string #}
    Hello {{ users }}!
{% endif %}