twig for else code example
Example 1: twig if else
{% if process_1 %}
{{ process_1 }}
{% elseif process_2 %}
Only {{ process_2 }} left!
{% else %}
Sold-out!
{% endif %}
Example 2: foreach twig
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
Example 3: twig for
<ul>
{% for key, user in users %}
<li>{{ key }}: {{ user.username|e }}</li>
{% endfor %}
</ul>
Example 4: twig loop
{% for user in users %}
{{ loop.index }} - {{ user.username }}
{% endfor %}
Example 5: twig if statement
{% if online == false %}
<p>Our website is in maintenance mode. Please, come back later.</p>
{% endif %}