Simple template engine in PHP I tried writing my very first template engine today. I designed it to just replace variables in templates, and keep it basic for now. Can anyone give me some constructive criticism? 

I'm getting ready to write my own mini framework, and want to improve as much as I can. I just need to know if this is the default way (logic) to write one, or is there a better way?

&lt;?php 

class Template {

    public $variables = [];

    public function assign($key, $value) {
        $this-&gt;variables[$key] = $value;
    }

    public function render($template, $variables = []) {
        if (empty($variables)) {
            $variables = $this-&gt;variables;
        }

        $code = file_get_contents($template);

        foreach ($this-&gt;variables as $key =&gt; $variable) {
            $code = str_replace('%' . $key . '%', $this-&gt;variables[$key], $code);
        }

        return $code;
    }
}
This template is either unusable or would make you write HTML in the business logic part  spoiling the whole idea.

A template engine is a more complex application than people often think. There is always a presentation logic that could be quite complex. Which means a template must support programming statements. At least loops and conditions. Without them, it will be almost unusable.

Imagine you need to list 10 posts an a blog. How it could be done in your template? Going to add all the HTML formatting to variables before assigning them? Really?

So, such a simple template could be made viable only by letting PHP to interpret the template. So it could be like

public function render($template, $variables = []) {
    array_merge($this-&gt;variables, $variables);
    extract($variables)
    ob_start();
    include $template;
    return ob_get_clean();
}


this way you will be able to use full featured templates that will contain all the logic needed for the presentation of your data.