twig for code example
Example 1: twig for
<ul>
{% for key, user in users %}
<li>{{ key }}: {{ user.username|e }}</li>
{% endfor %}
</ul>
Example 2: twig loop variables
{% for user in users %}
{{ loop.index }} - {{ user.username }}
{% endfor %}
Example 3: how to for loop twig
{% for letter in 'a'..'z' %}
* {{ letter }}
{% endfor %}
Example 4: how to for loop twig
{% for i in 0..10 %}
* {{ i }}
{% endfor %}
Example 5: twig for
{% for i in 0..10 %}
* {{ i }}
{% endfor %}
Example 6: modele de twig html : payant
<?php
include 'vendor/autoload.php';
try {
$loader = new Twig\Loader\FilesystemLoader('templates');
$twig = new Twig\Environment($loader);
$template = $twig->load('Menu.html');
echo $template->render(array(
'lundi' => 'Steak Frites',
'mardi' => 'Raviolis',
'mercredi' => 'Pot au Feu',
'jeudi' => 'Couscous',
'vendredi' => 'Poisson',
));
} catch (Exception $e) {
die ('ERROR: ' . $e->getMessage());
}