class StringLoader
Loads string templates, also known as inline templates.
This loader is intended to be used in a Twig loader chain and only loads string templates that begin with the following comment:
{# inline_template_start #}
This class override ensures that the string loader behaves as expected in the loader chain. If Twig's string loader is used as is, any string (even a reference to a file-based Twig template) is treated as a valid template and is rendered instead of a \Twig\Error\LoaderError exception being thrown.
Hierarchy
- class \Drupal\Core\Template\Loader\StringLoader implements \Twig\Loader\LoaderInterface
Expanded class hierarchy of StringLoader
See also
\Drupal\Core\Template\TwigEnvironment::renderInline()
\Drupal\Core\Render\Element\InlineTemplate
File
-
core/
lib/ Drupal/ Core/ Template/ Loader/ StringLoader.php, line 26
Namespace
Drupal\Core\Template\LoaderView source
class StringLoader implements LoaderInterface {
/**
* {@inheritdoc}
*/
public function exists($name) {
if (str_starts_with($name, '{# inline_template_start #}')) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* {@inheritdoc}
*/
public function getCacheKey(string $name) : string {
return $name;
}
/**
* {@inheritdoc}
*/
public function isFresh(string $name, int $time) : bool {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getSourceContext(string $name) : Source {
$name = (string) $name;
return new Source($name, $name);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
StringLoader::exists | public | function | Overrides LoaderInterface::exists | |
StringLoader::getCacheKey | public | function | Gets the cache key to use for the cache for a given template name. | Overrides LoaderInterface::getCacheKey |
StringLoader::getSourceContext | public | function | Returns the source context for a given template logical name. | Overrides LoaderInterface::getSourceContext |
StringLoader::isFresh | public | function | Overrides LoaderInterface::isFresh |