hook_render_template

hook_render_template($template_file, $variables)

Render a template using the theme engine.

Parameters

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

Hooks
Define functions that alter the behavior of Drupal core.

File

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

Code

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

  return $twig_service->loadTemplate($template_file)->render($variables);
}
doc_Drupal
2016-10-29 09:18:28
Comments
Leave a Comment

Please login to continue.