php-website-framework/lib/Page.php

70 lines
1.4 KiB
PHP

<?php
class Page
{
private $pagecontent = '';
private $title = '';
private $navigation = '';
private $style = '';
//default boilerplate html code
private $template = '
<!DOCTYPE html>
<html lang="de">
<head>
<title>$$TITLE$$</title>
$$STYLE$$
</head>
<body>
<nav>
$$NAVIGATION$$
</nav>
<div>
$$PAGECONTENT$$
</div>
</body>
</html>
';
public function __construct()
{
}
public function __destruct($title)
{
$this->title = $title;
}
public function addContent($content)
{
$this->pagecontent .= $content;
}
public function setTemplate($template)
{
$this->template = $template;
}
public function setNavigation($navigation)
{
$this->navigation = $navigation;
}
public function addStylesheet($stylesheet)
{
$this->style .= '<link rel="stylesheet" href="' . $stylesheet . '">';
}
public function displayPage()
{
$page = $this->template;
$page = str_replace('$$TITLE$$', $this->title, $page);
$page = str_replace('$$STYLE$$', $this->style, $page);
$page = str_replace('$$NAVIGATION$$', $this->navigation, $page);
$page = str_replace('$$PAGECONTENT$$', $this->pagecontent, $page);
echo $page;
}
}