aboutsummaryrefslogtreecommitdiff
path: root/src/View/class-template.php
blob: ea75648d670708f7c366caf6d3977516f8f7da64 (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
36
37
38
39
<?php

namespace HN\View;

/**
 * Template View
 *
 * @author cmc <hello@cleberg.net>
 */
class Template
{
	public function __construct(string $canonical_url, string $page_description, string $page_title, string $content_col)
	{
		$this->canonical_url = $canonical_url;
		$this->description = $page_description;
		$this->title = $page_title;
		$this->content = $content_col;
		$this->current_year = date("Y");
	}

	public function echo_template()
	{
		// Get the template file
		$template_file = 'templates/template.html';
		$page = file_get_contents($template_file);

		// 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->canonical_url, $page);
		$page = str_replace('{content}', $this->content, $page);
		$page = str_replace('{current_year}', $this->current_year, $page);

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

// EOF