public TwigEnvironment::renderInline($template_string, array $context = array())
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.
Parameters
string $template_string: The template string to render with placeholders.
array $context: An array of parameters to pass to the template.
Return value
\Drupal\Component\Render\MarkupInterface|string The rendered inline template as a Markup object.
See also
\Drupal\Core\Template\Loader\StringLoader::exists()
File
- core/lib/Drupal/Core/Template/TwigEnvironment.php, line 113
Class
- TwigEnvironment
- A class that defines a Twig environment for Drupal.
Namespace
Drupal\Core\Template
Code
public function renderInline($template_string, array $context = array()) { // Prefix all inline templates with a special comment. $template_string = '{# inline_template_start #}' . $template_string; return Markup::create($this->loadTemplate($template_string, NULL)->render($context)); }
Please login to continue.