public function setTemplateDirectory($directory)
    {
        // The directory will be null if a template is being loaded from storage.
        if ($directory == null) {
            $this->templateDirectory = realpath(find_tse_template($this->templateName));
            $this->loadPackageTemplate($this->templateDirectory);
            return;
        }

        $this->templateDirectory = realpath($directory);
        $this->loadPackageTemplate(realpath($directory));
    }