/Drupal 8

function hook_render_template

hook_render_template($template_file, $variables)

Render a template using the theme engine.


string $template_file: The path (relative to the Drupal root directory) to the template to be rendered including its extension in the format 'path/to/TEMPLATE_NAME.EXT'.

array $variables: A keyed array of variables that are available for composing the output. The theme engine is responsible for passing all the variables to the template. Depending on the code in the template, all or just a subset of the variables might be used in the template.

Return value

string The output generated from the template. In most cases this will be a string containing HTML markup.

Related topics

Define functions that alter the behavior of Drupal core.


core/lib/Drupal/Core/Render/theme.api.php, line 779
Hooks and documentation related to the theme and render system.


function hook_render_template($template_file, $variables) {
  $twig_service = \Drupal::service('twig');

  return $twig_service->loadTemplate($template_file)->render($variables);

© 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.