set variable in twig code example
Example 1: twig is set variable
{
{% if foo is defined %}
...
{% endif %}
{
{% if foo.bar is defined %}
...
{% endif %}
{% if foo['bar'] is defined %}
...
{% endif %}
Example 2: comment in twig
{
{% for user in users %}
...
{% endfor %}
Example 3: 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());
}