twig varialbe++ code example
Example 1: twig if
{% if online == false %}
<p>Our website is in maintenance mode. Please, come back later.</p>
{% endif %}
Example 2: modele de twig html : payant
<?php
// menu.php
// inclure l'autoloader
include 'vendor/autoload.php';
try {
// le dossier ou on trouve les templates
$loader = new Twig\Loader\FilesystemLoader('templates');
// initialiser l'environement Twig
$twig = new Twig\Environment($loader);
// load template
$template = $twig->load('Menu.html');
// set template variables
// render template
echo $template->render(array(
'lundi' => 'Steak Frites',
'mardi' => 'Raviolis',
'mercredi' => 'Pot au Feu',
'jeudi' => 'Couscous',
'vendredi' => 'Poisson',
));
} catch (Exception $e) {
die ('ERROR: ' . $e->getMessage());
}