Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By khurrami on
Load and render a twig template
$twig = \Drupal::service('twig');
$template = $twig->loadTemplate('path/to/your_template.html.twig');
$response = $template->render(['var1' => $var1, 'var2' => $var2]);
return $response;
var1 & var2 will also be pass as variable to twig template which we can use as follow
{{ var1 }}
Comments
=-=
per https://www.drupal.org/node/643758 please edit your post and move it to the 'post installation' forum. Thank you.