HTML Templates with Substitutable Areas - PHP In order to separate my views (markup) and code, I elected to write my views like this:

    &lt;!DOCTYPE HTML&gt;
    &lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;%PAGE_TITLE%&lt;/title&gt;
        &lt;meta charset="UTF-8"&gt;
        &lt;link href='PotatoDocs/views/stylesheets/docs2013.css' type='text/css' rel='stylesheet'&gt;
        &lt;link rel="shortcut icon" href="favicon.ico" /&gt;

        &lt;link rel="stylesheet" href="highlight.js/styles/default.css"&gt;
        &lt;script src="highlight.js/highlight.pack.js"&gt;&lt;/script&gt;
        &lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;section id='wrapper'&gt;
            &lt;section id='content'&gt;
                &lt;h1&gt;%PAGE_TITLE%&lt;/h1&gt;
                %CONTENT%
            &lt;/section&gt;

            &lt;section id='sidebar'&gt;
                %SIDEBAR%
            &lt;/section&gt;  

            &lt;div class='clear'&gt;&amp;nbsp;&lt;/div&gt;

        &lt;/section&gt;


        &lt;section id='footer'&gt;
            Potato Seed 2013
        &lt;/section&gt;
    &lt;/body&gt;
    &lt;/html&gt;


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-&gt;template_dir . "/main.html");

        $page_content = str_replace("%PAGE_TITLE%", pdisplay($page_title), $page_template);
        $page_content = str_replace("%CONTENT%", $this-&gt;pagecontent_content, $page_content);
        $page_content = str_replace("%SIDEBAR%", $this-&gt;sidebar_content, $page_content);

        $this-&gt;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.
According your comment you don't want to use a template engine, but are actually creating a new one. At some point you will need loops or ifs and it starts becoming ugly.

PHP is already a template engine. Actually it was designed for exactly this purpose. There is a braceless/echoless syntax for all control structures.

Your template/view:

&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;?=$page_title?&gt;&lt;/title&gt;
    ...
&lt;/head&gt;
&lt;body&gt;
    &lt;section id='wrapper'&gt;
        &lt;section id='content'&gt;
            &lt;h1&gt;&lt;?=$page_title?&gt;&lt;/h1&gt;
            &lt;?=$content?&gt;
        &lt;/section&gt;
     ...
&lt;/body&gt;
&lt;/html&gt;


Your controller:

private function generatePageSource($page_title)
{
    $page_title=pdisplay($page_title));
    $content = $this-&gt;pagecontent_content;

    ob_start();
    $template=REGISTRY_CODE_PATH . "views/templates/" .
        $this-&gt;template_dir . "/main.html";
    include $template;
    $this-&gt;page_content=ob_get_clean();
}


Of course you could wrap this in a View class to DRY.