function TwigEnvironment::getTemplateClass

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Template/TwigEnvironment.php \Drupal\Core\Template\TwigEnvironment::getTemplateClass()
  2. 10 core/lib/Drupal/Core/Template/TwigEnvironment.php \Drupal\Core\Template\TwigEnvironment::getTemplateClass()
  3. 11.x 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 197

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];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.