public function render($file, $env = array()) {
        $file = $this->views_path . '/' . $file;

        if(!file_exists($file)) {
            throw new \Exception("Could not compile $file, file not found");
        }

        // Cache compiled HTML
        $cacheHash = md5($file . serialize($env));
        $cache_file = $this->views_cache . "/$cacheHash.cache";
        if( !$this->debug && (file_exists($cache_file) 
            && filemtime($cache_file) > filemtime($file))) {
            return file_get_contents($cache_file);
        }

        // If it's not cached, load compiled file and execute
        $this->currFile = $file;
        $hash = md5($file);
        $this->compile($file);
        $compiled_file = $this->views_cache . '/' . $hash;

        // Set a custom error handler
        set_error_handler(array($this, 'onTemplateError'));

        require_once($compiled_file);
        $output = call_user_func('katar_' . $hash, $env);

        // Restore the handler as we leave Katar
        restore_error_handler();

        file_put_contents($cache_file, $output);

        return $output;
    }