<?php

class nanoTpl
{
    protected $file;
    protected $values = array();

    public function __construct($file)
    {
        $file = "app/views/ordinaryMortals/".$file.".php";

        if(!file_exists($file)) {
            echo "Error loading template file ($file)).";
        } else {
            $this->file = file_get_contents($file);
        }
    }

    public function set($key, $value)
    {
        $this->values[$key] = $value;
    }

    public function setArray($array)
    {
        foreach($array as $key => $value) {
            $this->values[$key] = $value;
        }
    }

    public function output()
    {
        $output = $this->file;

        foreach($this->values as $key => $value) {
            $tag_to_replace = "{{".$key."}}";
            $output = str_replace($tag_to_replace, $value, $output);
        }
        return $output;
    }

}