4 The ``if`` statement in Twig is comparable with the if statements of PHP.
6 In the simplest form you can use it to test if an expression evaluates to
11 {% if online == false %}
12 <p>Our website is in maintenance mode. Please, come back later.</p>
15 You can also test if an array is not empty:
21 {% for user in users %}
22 <li>{{ user.username|e }}</li>
29 If you want to test if the variable is defined, use ``if users is
32 You can also use ``not`` to check for values that evaluate to ``false``:
36 {% if not user.subscribed %}
37 <p>You are not subscribed to our mailing list.</p>
40 For multiple conditions, ``and`` and ``or`` can be used:
44 {% if temperature > 18 and temperature < 27 %}
45 <p>It's a nice day for a walk in the park.</p>
48 For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can
49 use more complex ``expressions`` there too:
55 {% elseif kenny.dead %}
56 You killed Kenny! You bastard!!!
58 Kenny looks okay --- so far
63 The rules to determine if an expression is ``true`` or ``false`` are the
64 same as in PHP; here are the edge cases rules:
66 ====================== ====================
67 Value Boolean evaluation
68 ====================== ====================
71 whitespace-only string true
76 ====================== ====================