krz/php-blog

A PHP blogging system with built-in static comments.

clone: git clone https://gitbay.org/krz/php-blog.git

main: _classes/Template.php · raw

 1<?php
 2
 3
 4class Template
 5{
 6    public function __construct(string $canonicalURL, string $pageDescription, string $pageTitle, string $pageExtras, string $contentCol, string $commentSection)
 7    {
 8        $this->canonicalURL = $canonicalURL;
 9        $this->description = $pageDescription;
10        $this->title = $pageTitle;
11        $this->extras = $pageExtras;
12        $this->content = $contentCol;
13        $this->comments = $commentSection;
14        $this->currentYear = date("Y");
15    }
16
17    public function echoTemplate()
18    {
19        // Get the template file
20        $templateFile = '_templates/template.html';
21        $page = file_get_contents($templateFile);
22
23        // Replace the template variables
24        $page = str_replace('{Page_Title}', $this->title, $page);
25        $page = str_replace('{Page_Description}', $this->description, $page);
26        $page = str_replace('{Canonical_URL}', $this->canonicalURL, $page);
27        $page = str_replace('{Page_Extras}', $this->extras, $page);
28        $page = str_replace('{Content_Column}', $this->content, $page);
29        $page = str_replace('{User_Comments}', $this->comments, $page);
30        $page = str_replace('{Current_Year}', $this->currentYear, $page);
31
32        // Echo the filled-out template
33        echo $page;
34    }
35}