class StringLoader in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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, \Drupal\Core\Template\Loader\Twig_ExistsLoaderInterface
Expanded class hierarchy of StringLoader
See also
\Drupal\Core\Template\TwigEnvironment::renderInline()
\Drupal\Core\Render\Element\InlineTemplate
2 files declare their use of StringLoader
- TwigExtensionTest.php in core/
tests/ Drupal/ Tests/ Core/ Template/ TwigExtensionTest.php - Contains \Drupal\Tests\Core\Template\TwigExtensionTest.
- 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 28 - Contains \Drupal\Core\Template\Loader\StringLoader.
Namespace
Drupal\Core\Template\LoaderView source
class StringLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface {
/**
* {@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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringLoader:: |
public | function | ||
StringLoader:: |
public | function | ||
StringLoader:: |
public | function | ||
StringLoader:: |
public | function |