Twig tags
Met tags kun je logica toevoegen aan je template, zoals for loops en if statements. Hieronder staan de meest gebruikte tags binnen het webshop template uitgelicht. Voor meer tags kun je de Twig documentatie over Tags bekijken.
Wil je gebruik maken van tags die niet hieronder zijn genoemd? Probeer ze dat eerst in een template uit dat niet aan een live website is gekoppeld. Sommige tags zijn niet bij ons beschikbaar, zoals de Sandbox tag, of zijn in latere versies van Twig toegevoegd dan wij gebruiken.
For loops
```twig
<h1>Members</h1>
<ul>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
</ul>
twig docs: [https://twig.symfony.com/doc/3.x/tags/for.html](https://twig.symfony.com/doc/3.x/tags/for.html)
## If statements
{% if product.stock > 10 %}
Available
{% elseif product.stock > 0 %}
Only {{ product.stock }} left!
{% else %}
Sold-out!
{% endif %}
twig docs: [https://twig.symfony.com/doc/3.x/tags/if.html](https://twig.symfony.com/doc/3.x/tags/if.html)
## Include
{% include 'header.html' %}
Body
{% include 'footer.html' %}
twig docs: [https://twig.symfony.com/doc/3.x/tags/extends.html](https://twig.symfony.com/doc/3.x/tags/extends.html)
## Set
{% set foo = 'bar' %}
twig docs: [https://twig.symfony.com/doc/3.x/tags/set.html](https://twig.symfony.com/doc/3.x/tags/set.html)
## Extends
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
{{ parent() }}
<style type="text/css">
.important { color: #336699; }
</style>
{% endblock %}
{% block content %}
<h1>Index</h1>
<p class="important">
Welcome on my awesome homepage.
</p>
{% endblock %}
twig docs: [https://twig.symfony.com/doc/3.x/tags/extends.html](https://twig.symfony.com/doc/3.x/tags/extends.html)
## Macro
{% macro input(name, value, type = "text", size = 20) %}
<input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}"/>
{% endmacro %}
twig docs: [https://twig.symfony.com/doc/3.x/tags/macro.html](https://twig.symfony.com/doc/3.x/tags/macro.html)