-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
47 lines (40 loc) · 1.35 KB
/
index.php
File metadata and controls
47 lines (40 loc) · 1.35 KB
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
<?php
/* Entry point for our template parser
* Just here to add some general accessibility to our template parser's functionality.
*/
use Parser\TemplateParser;
use Helpers\TemplateHelper;
// Register Autoloads so we don't have to bother with includes for our namespaces
spl_autoload_register(function($className) {
include_once __DIR__ . '/' . $className . '.php';
});
// Are we trying to access a template?
$template = $_GET['template'] ?? null;
// If no template is selected, we'll want to write a list of links to select one
if ($template === null)
{
// Get all the templates
$templateFiles = TemplateHelper::getTemplates();
// Go through each template file and create a link for that template
foreach ($templateFiles AS $templateName)
{
/*
Write our link.
Technically we'd probably want a full HTML page structure, but let's ignore that for simplicity.
*/
echo '<a href="index.php?template=' . $templateName . '">' . $templateName . '<a>';
echo '<br>';
}
}
else
{
// The page data we want to show in our template. Normally this obviously wouldn't be hard coded.
$pageData = array(
'page_title' => 'Template Parser Test',
'page_header' => 'Header for template',
'page_text' => 'This is some test data for a template'
);
$parser = new TemplateParser;
// Parse and display our template
echo $parser->parseTemplate($template, $pageData);
}