private function loadStringTemplate(\Twig_Environment $environment, $template)
    {
        $existingLoader = $environment->getLoader();
        $environment->setLoader($this->stringLoader);

        try {
            $template = $environment->loadTemplate($template);
        } catch (\Exception $e) {
            $environment->setLoader($existingLoader);
            
            throw $e;
        }

        $environment->setLoader($existingLoader);

        return $template;
    }