Skip to content

Commit e28e5f2

Browse files
committed
Install twig into index.php
1 parent e52fe63 commit e28e5f2

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

index.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
// connection
1010
$db = connectDB();
1111

12-
// test Twig
13-
$loader = new \Twig\Loader\ArrayLoader([
14-
'index' => '<html>Coucou {{ name }} {{ surname }}!</html>',
12+
// Twig loading
13+
// link to template's folder
14+
$loader = new \Twig\Loader\FilesystemLoader('view');
15+
// create Twig Environment
16+
$twig = new \Twig\Environment($loader, [
17+
/*
18+
'cache' => '/path/to/compilation_cache',
19+
*/
1520
]);
16-
$twig = new \Twig\Environment($loader);
1721

18-
echo $twig->render('index', ['name' => 'Michaël','surname'=>"Pitz"]);
22+
echo $twig->render('base.html.twig', ['name' => 'Michaël']);

view/base.html.twig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Titre</title>
6+
</head>
7+
<body>
8+
coucou {{ name }}
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)