You are here

function _twig_render in Twig Input Filter 7

Renders a template with a given context.

2 calls to _twig_render()
twig_process_node in ./twig.module
Processes variables for node.tpl.php.
_twig_filter in ./twig.filter.inc
Callback: performs Twig rendering.

File

./twig.utils.inc, line 11
Helper functions for the Twig module.

Code

function _twig_render($template, $context) {
  $path = libraries_get_path('twig');
  if (!$path) {
    drupal_set_message("Can't find `twig` library.", 'error');
    return;
  }
  require_once $path . '/lib/Twig/Autoloader.php';
  Twig_Autoloader::register();
  $templates = _twig_get_db_templates();
  if (is_array($template)) {
    $templates['_'] = $template['template'];
    $template = '_';
  }
  $loader = new Twig_Loader_Array($templates);
  $twig = new Twig_Environment($loader, array());
  return $twig
    ->render($template, $context);
}