public function TwigEnvironment::getTemplateClass in Drupal 9
Same name and namespace in other branches
- 8 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 198
Class
- TwigEnvironment
- A class that defines a Twig environment for Drupal.
Namespace
Drupal\Core\TemplateCode
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];
}