+ if (isset($this->loading[$cls])) {
+ throw new Twig_Error_Runtime(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, array($name)))));
+ }
+
+ $this->loading[$cls] = $name;
+
+ try {
+ $this->loadedTemplates[$cls] = new $cls($this);
+ unset($this->loading[$cls]);
+ } catch (\Exception $e) {
+ unset($this->loading[$cls]);
+
+ throw $e;
+ }
+
+ return $this->loadedTemplates[$cls];