public function loadTemplate($name, $index = null)
    {
        $cls = $this->getTemplateClass($name, $index);

        if (isset($this->loadedTemplates[$cls])) {
            return $this->loadedTemplates[$cls];
        }

        if (!class_exists($cls, false)) {
            if (false === $cache = $this->getCacheFilename($name)) {
                eval('?>'.$this->compileSource($this->getLoader()->getSource($name), $name));
            } else {
                if (!is_file($cache) || ($this->isAutoReload() && !$this->isTemplateFresh($name, filemtime($cache)))) {
                    $this->writeCacheFile($cache, $this->compileSource($this->getLoader()->getSource($name), $name));
                }

                require_once $cache;
            }
        }

        if (!$this->runtimeInitialized) {
            $this->initRuntime();
        }

        return $this->loadedTemplates[$cls] = new $cls($this);
    }
public function loadTemplate($name, $index = null)
    {
        $cls = $this->getTemplateClass($name, $index);

        if (isset($this->loadedTemplates[$cls])) {
            return $this->loadedTemplates[$cls];
        }

        if (!class_exists($cls, false)) {
            if (false === $cache = $this->getCacheFilename($name)) {
                eval('?>'.$this->compileSource($this->getLoader()->getSource($name), $name));
            } else {
                if (!is_file($cache) || ($this->isAutoReload() && !$this->isTemplateFresh($name, filemtime($cache)))) {
                    $this->writeCacheFile($cache, $this->compileSource($this->getLoader()->getSource($name), $name));
                }

                require_once $cache;
            }
        }

        if (!$this->runtimeInitialized) {
            $this->initRuntime();
        }

        return $this->loadedTemplates[$cls] = new $cls($this);
    }
public function loadTemplate ( $ name , $ index = null ) { $ cls = $ this -> getTemplateClass ( $ name , $ index ) ; if ( isset ( $ this -> loadedTemplates [ $ cls ] ) ) { return $ this -> loadedTemplates [ $ cls ] ; } if ( ! class_exists ( $ cls , false ) ) { if ( false === $ cache = $ this -> getCacheFilename ( $ name ) ) { eval ( '?>' . $ this -> compileSource ( $ this -> getLoader ( ) -> getSource ( $ name ) , $ name ) ) ; } else { if ( ! is_file ( $ cache ) || ( $ this -> isAutoReload ( ) && ! $ this -> isTemplateFresh ( $ name , filemtime ( $ cache ) ) ) ) { $ this -> writeCacheFile ( $ cache , $ this -> compileSource ( $ this -> getLoader ( ) -> getSource ( $ name ) , $ name ) ) ; } require_once $ cache ; } } if ( ! $ this -> runtimeInitialized ) { $ this -> initRuntime ( ) ; } return $ this -> loadedTemplates [ $ cls ] = new $ cls ( $ this ) ; }
Loads a template by name.

@param string  $name  The template name
@param integer $index The index if it is an embedded template

@return Twig_TemplateInterface A template instance representing the given template name

@throws Twig_Error_Loader When the template cannot be found
@throws Twig_Error_Syntax When an error occurred during compilation
Loads a template by name .