public function locateViewFile($filename, $requiredNamespace = '')
    {
        foreach ($this->templateSearchDirectories as $namespace => $location) {
            if (!empty($requiredNamespace) && ($namespace != $requiredNamespace)) {
                continue;
            }

            $fullFilename = $location . DIRECTORY_SEPARATOR . str_replace('..', '', $filename);

            if (!$this->allowRecursion && ($fullFilename == $this->parentTemplate)) {
                if (!empty($this->log))
                {
                    $this->log->error("Disallowed template recursion found in filename " . $filename . ". To allow recursion, send _allowRecursion=true into the template data.");
                }
                return '';
            }

            if (is_file($fullFilename)) {
                return $fullFilename;
            }
        }

        if (!empty($this->log))
        {
            $this->log->error("Invalid template filename specified " . $filename);
        }

        return '';
    }