protected function locateTemplateFilePath($filename)
    {
        // Search project root template directory if defined.
        if ($this->hasProjectTemplateDirectory()) {
            $filepath = $this->templateProjectPath() . "/{$filename}";

            if (file_exists($filepath)) {
                return $filepath;
            }
        }

        // Search defined directories for template files.
        foreach ($this->searchDirectories as $directory) {
            if (!file_exists($directory)) {
                continue;
            }
            $filepath = "{$directory}/{$filename}";

            if (file_exists($filepath)) {
                return $filepath;
            }
        }

        return null;
    }