You are here

public function TwigEnvironment::getTemplateClass in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Template/TwigEnvironment.php \Drupal\Core\Template\TwigEnvironment::getTemplateClass()

Gets the template class associated with the given string.

Parameters

string $name: The name for which to calculate the template class name.

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

Return value

string The template class name.

File

core/lib/Drupal/Core/Template/TwigEnvironment.php, line 84
Contains \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] = $this->templateClassPrefix . hash('sha256', $this->loader
      ->getCacheKey($name)) . (NULL === $index ? '' : '_' . $index);
  }
  return $this->templateClasses[$cache_index];
}