public function TwigEnvironment::getTemplateClass

1 call to TwigEnvironment::getTemplateClass()
TwigEnvironment::loadTemplate in drupal/core/lib/Drupal/Core/Template/TwigEnvironment.php
Implements Twig_Environment::loadTemplate().

File

drupal/core/lib/Drupal/Core/Template/TwigEnvironment.php, line 125
Definition of Drupal\Core\Template\TwigEnvironment.

Class

TwigEnvironment
A class that defines a Twig environment for Drupal.

Namespace

Drupal\Core\Template

Code

public function getTemplateClass($name, $index = null) {

  // We override this method to add caching because it gets called multiple
  // times when the same template is used more than once. For example, a page
  // rendering 50 nodes without any node template overrides will use the same
  // node.html.twig for the output of each node and the same compiled class.
  $cache_index = $name . (NULL === $index ? '' : '_' . $index);
  if (!isset($this->templateClasses[$cache_index])) {
    $this->templateClasses[$cache_index] = parent::getTemplateClass($name, $index);
  }
  return $this->templateClasses[$cache_index];
}