private function getTemplateEngineInstance()
    {
        $teConfig = $this->getComponentConfig('TemplateEngine', 'Engines', false);

        // fallback to default template engine
        if (!$teConfig) {
            $defaultTemplateEngineConfig = [
                'Engines' => [
                    'Smarty' => [
                        'ForceCompile'     => false,
                        'CacheDir'         => $this->getAbsolutePath() . 'App/Cache/Smarty/Cache',
                        'CompileDir'       => $this->getAbsolutePath() . 'App/Cache/Smarty/Compile',
                        'TemplateDir'      => $this->getAbsolutePath() . 'App/Layouts',
                        'AutoEscapeOutput' => false,
                    ]
                ]
            ];

            TemplateEngine::setConfig(new ConfigObject($defaultTemplateEngineConfig));

            return TemplateEngineLoader::getInstance('Smarty');
        }

        $teConfig = $this->getComponentConfig('TemplateEngine', 'Engines')->toArray();
        reset($teConfig);
        $teName = key($teConfig);

        return TemplateEngineLoader::getInstance($teName);
    }