3 namespace Drupal\Core\Render\Element;
6 * Provides a render element where the user supplies an in-line Twig template.
9 * - #template: The inline Twig template used to render the element.
10 * - #context: (array) The variables to substitute into the Twig template.
11 * Each variable may be a string or a render array.
16 * '#type' => 'inline_template',
17 * '#template' => "{% trans %} Hello {% endtrans %} <strong>{{name}}</strong>",
24 * @RenderElement("inline_template")
26 class InlineTemplate extends RenderElement {
31 public function getInfo() {
32 $class = get_class($this);
35 [$class, 'preRenderInlineTemplate'],
43 * Renders a twig string directly.
45 * @param array $element
49 public static function preRenderInlineTemplate($element) {
50 /** @var \Drupal\Core\Template\TwigEnvironment $environment */
51 $environment = \Drupal::service('twig');
52 $markup = $environment->renderInline($element['#template'], $element['#context']);
53 $element['#markup'] = $markup;