TwigEnvironment
class TwigEnvironment extends Environment (View source)
A class that defines a Twig environment for Drupal.
Instances of this class are used to store the configuration and extensions, and are used to load templates from the file system or other locations.
Constants
| CACHE_PREFIX_METADATA_KEY |
Key name of the Twig cache prefix metadata key-value pair in State. |
Properties
| protected StateInterface | $state | The state service. |
|
| protected array | $templateClasses | Static cache of template classes. |
|
| protected string | $twigCachePrefix | The template cache filename prefix. |
Methods
Constructs a TwigEnvironment object and stores cache and storage internally.
{@inheritdoc}
Invalidates all compiled Twig templates.
Get the cache prefixed used by \Drupal\Core\Template\TwigPhpStorageCache.
Retrieves metadata associated with a template.
Gets the template class associated with the given string.
Renders a twig string directly.
Details
__construct(string $root, CacheBackendInterface $cache, string $twig_extension_hash, StateInterface $state, LoaderInterface $loader, array $options = [])
Constructs a TwigEnvironment object and stores cache and storage internally.
compileSource(Source $source)
{@inheritdoc}
invalidate()
Invalidates all compiled Twig templates.
string
getTwigCachePrefix()
Get the cache prefixed used by \Drupal\Core\Template\TwigPhpStorageCache.
array
getTemplateMetadata(string $name)
Retrieves metadata associated with a template.
string
getTemplateClass(string $name, int $index = NULL)
Gets the template class associated with the given string.
MarkupInterface|string
renderInline(string $template_string, array $context = [])
Renders a twig string directly.
Warning: You should use the render element 'inline_template' together with the #template attribute instead of this method directly. On top of that you have to ensure that the template string is not dynamic but just an ordinary static php string, because there may be installations using read-only PHPStorage that want to generate all possible twig templates as part of a build step. So it is important that an automated script can find the templates and extract them. This is only possible if the template is a regular string.