In order to separate my views (markup) and code, I elected to write my views like this:
<!DOCTYPE HTML>
<html>
<head>
<title>%PAGE_TITLE%</title>
<meta charset="UTF-8">
<link href='PotatoDocs/views/stylesheets/docs2013.css' type='text/css' rel='stylesheet'>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" href="highlight.js/styles/default.css">
<script src="highlight.js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<section id='wrapper'>
<section id='content'>
<h1>%PAGE_TITLE%</h1>
%CONTENT%
</section>
<section id='sidebar'>
%SIDEBAR%
</section>
<div class='clear'> </div>
</section>
<section id='footer'>
Potato Seed 2013
</section>
</body>
</html>
A method then replaces the substitution area with parts of the website, like so:
private function generatePageSource($page_title)
{
$page_template = file_get_contents(REGISTRY_CODE_PATH . "views/templates/" .
$this->template_dir . "/main.html");
$page_content = str_replace("%PAGE_TITLE%", pdisplay($page_title), $page_template);
$page_content = str_replace("%CONTENT%", $this->pagecontent_content, $page_content);
$page_content = str_replace("%SIDEBAR%", $this->sidebar_content, $page_content);
$this->page_content = $page_content;
}
The $this->page_content is later echoed.
Not too relevant to my question, but for the sake of completion, this is the pdisplay() function.
function pdisplay($pdisplay)
{
$pdisplay = htmlentities(stripslashes($pdisplay), ENT_QUOTES);
return $pdisplay;
}
My question is this (though I accept any code criticism at all): is this a sensible way to render pages?
I used to implant php tags with echoes onto a page -- but this meant that code (even a little bit) was on the views, so I thought this would be a better solution.