-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
51 lines (45 loc) · 1.37 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require 'vendor/autoload.php'; // Composer's autoloader
// Create a Twig environment
$loader = new \Twig\Loader\FilesystemLoader('views');
$twig = new \Twig\Environment($loader);
$request_uri = $_SERVER['REQUEST_URI'];
// basic routing
if ($request_uri === '/') {
// Render the home page
echo $twig->render('home.html.twig');
} elseif ($request_uri === '/variables') {
// Render the page with variables
echo $twig->render(
'variables.html.twig',
array(
'name' => 'John Doe',
'age' => 25,
)
);
} elseif ($request_uri === '/conditionals') {
// Render the page with conditionals
echo $twig->render('conditionals.html.twig', array(
'name' => 'John Doe',
'age' => 25,
)
);
} elseif ($request_uri === '/loops') {
// Render the page with loops
echo $twig->render('loops.html.twig', array(
'users' => array(
array('name' => 'Maxine', 'age' => 32, 'role' => 'admin'),
array('name' => 'Anna', 'age' => 17, 'role' => 'user'),
array('name' => 'John', 'age' => 58, 'role' => 'user'),
)
)
);
} elseif ($request_uri === "/templates") {
// Render the page with templates
echo $twig->render('templates.html.twig'
);
} else {
// Handle 404 - Page not found
http_response_code(404);
echo $twig->render('404.html.twig');
}