Twig

The flexible, fast, and secure
template engine for PHP

a Symfony Product
Docs mapping
You are reading the documentation for Twig 3.x. Switch to the documentation for Twig 1.x, 2.x.

Questions & Feedback

License

Twig documentation is licensed under the new BSD license.

mapping

mapping checks if a variable is a mapping:

1
2
3
4
5
6
7
{% set users = {alice: "Alice Dupond", bob: "Bob Smith"} %}
{# evaluates to true if the users variable is a mapping #}
{% if users is mapping %}
    {% for key, user in users %}
        {{ key }}: {{ user }};
    {% endfor %}
{% endif %}