class 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

See also

\Drupal\Core\Template\TwigEnvironment::renderInline()

\Drupal\Core\Render\Element\InlineTemplate

twig_render_template()

File

core/lib/Drupal/Core/Template/Loader/StringLoader.php, line 23

Namespace

Drupal\Core\Template\Loader

Members

Name Modifiers Type Description
StringLoader::exists public function Check if we have the source code of a template, given its name. Overrides Twig_ExistsLoaderInterface::exists
StringLoader::getCacheKey public function Gets the cache key to use for the cache for a given template name. Overrides Twig_LoaderInterface::getCacheKey
StringLoader::getSource public function Gets the source code of a template, given its name. Overrides Twig_LoaderInterface::getSource
StringLoader::isFresh public function Returns true if the template is still fresh. Overrides Twig_LoaderInterface::isFresh

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Template!Loader!StringLoader.php/class/StringLoader/8.1.x