class StringLoader in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Template/Loader/StringLoader.php \Drupal\Core\Template\Loader\StringLoader
Loads string templates, also known as inline templates.
This loader is intended to be used in a Twig loader chain and whitelists 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_Loader exception being thrown.
Hierarchy
- class \Drupal\Core\Template\Loader\StringLoader implements \Drupal\Core\Template\Loader\Twig_LoaderInterface, \Twig\Loader\ExistsLoaderInterface, \Twig\Loader\SourceContextLoaderInterface
Expanded class hierarchy of StringLoader
See also
\Drupal\Core\Template\TwigEnvironment::renderInline()
\Drupal\Core\Render\Element\InlineTemplate
3 files declare their use of StringLoader
- AttributeTest.php in core/
tests/ Drupal/ Tests/ Core/ Template/ AttributeTest.php - TwigExtensionTest.php in core/
tests/ Drupal/ Tests/ Core/ Template/ TwigExtensionTest.php - TwigSandboxTest.php in core/
tests/ Drupal/ Tests/ Core/ Template/ TwigSandboxTest.php - Contains \Drupal\Tests\Core\Template\TwigSandboxTest.
1 string reference to 'StringLoader'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses StringLoader
File
- core/
lib/ Drupal/ Core/ Template/ Loader/ StringLoader.php, line 27
Namespace
Drupal\Core\Template\LoaderView source
class StringLoader implements \Twig_LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface {
/**
* {@inheritdoc}
*/
public function exists($name) {
if (strpos($name, '{# inline_template_start #}') === 0) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* {@inheritdoc}
*/
public function getSource($name) {
return $name;
}
/**
* {@inheritdoc}
*/
public function getCacheKey($name) {
return $name;
}
/**
* {@inheritdoc}
*/
public function isFresh($name, $time) {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getSourceContext($name) {
$name = (string) $name;
return new Source($name, $name);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringLoader:: |
public | function | ||
StringLoader:: |
public | function | ||
StringLoader:: |
public | function | ||
StringLoader:: |
public | function | ||
StringLoader:: |
public | function |