You are here

public function Twig_Environment::loadTemplate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Environment.php \Twig_Environment::loadTemplate()

Loads a template by name.

Parameters

string $name The template name:

int $index The index if it is an embedded template:

Return value

Twig_TemplateInterface A template instance representing the given template name

Throws

Twig_Error_Loader When the template cannot be found

Twig_Error_Syntax When an error occurred during compilation

2 calls to Twig_Environment::loadTemplate()
Twig_Environment::createTemplate in vendor/twig/twig/lib/Twig/Environment.php
Creates a template from source.
Twig_Environment::resolveTemplate in vendor/twig/twig/lib/Twig/Environment.php
Tries to load a template consecutively from an array.

File

vendor/twig/twig/lib/Twig/Environment.php, line 376

Class

Twig_Environment
Stores the Twig configuration.

Code

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 ($this->bcGetCacheFilename) {
      $key = $this
        ->getCacheFilename($name);
    }
    else {
      $key = $this->cache
        ->generateKey($name, $cls);
    }
    if (!$this
      ->isAutoReload() || $this
      ->isTemplateFresh($name, $this->cache
      ->getTimestamp($key))) {
      $this->cache
        ->load($key);
    }
    if (!class_exists($cls, false)) {
      $content = $this
        ->compileSource($this
        ->getLoader()
        ->getSource($name), $name);
      if ($this->bcWriteCacheFile) {
        $this
          ->writeCacheFile($key, $content);
      }
      else {
        $this->cache
          ->write($key, $content);
      }
      eval('?>' . $content);
    }
  }
  if (!$this->runtimeInitialized) {
    $this
      ->initRuntime();
  }
  return $this->loadedTemplates[$cls] = new $cls($this);
}