aboutsummaryrefslogtreecommitdiff
path: root/_classes/Template.php
blob: 312e566d1695807a6ac90fa018b8c0c06393ff90 (plain) (blame)
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
<?php


class Template
{
    public function __construct(string $canonicalURL, string $pageDescription, string $pageTitle, string $pageExtras, string $contentCol, string $commentSection)
    {
        $this->canonicalURL = $canonicalURL;
        $this->description = $pageDescription;
        $this->title = $pageTitle;
        $this->extras = $pageExtras;
        $this->content = $contentCol;
        $this->comments = $commentSection;
        $this->currentYear = date("Y");
    }

    public function echoTemplate()
    {
        // Get the template file
        $templateFile = '_templates/template.html';
        $page = file_get_contents($templateFile);

        // Replace the template variables
        $page = str_replace('{Page_Title}', $this->title, $page);
        $page = str_replace('{Page_Description}', $this->description, $page);
        $page = str_replace('{Canonical_URL}', $this->canonicalURL, $page);
        $page = str_replace('{Page_Extras}', $this->extras, $page);
        $page = str_replace('{Content_Column}', $this->content, $page);
        $page = str_replace('{User_Comments}', $this->comments, $page);
        $page = str_replace('{Current_Year}', $this->currentYear, $page);

        // Echo the filled-out template
        echo $page;
    }
}