-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwig.engine
52 lines (45 loc) · 1.2 KB
/
twig.engine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @file
* Handles integration of Twig templates with the Drupal theme system.
*/
/**
* Implements hook_init().
*/
function twig_init($template) {
$file = dirname($template->filename) . '/template.php';
if (file_exists($file)) {
include_once DRUPAL_ROOT . '/' . $file;
}
}
/**
* Implements hook_theme().
*/
function twig_theme($existing, $type, $theme, $path) {
$templates = drupal_find_theme_templates($existing, twig_extension(), $path);
$paths = array_map(function ($value) { return $value['path']; }, array_values($templates));
$paths = array_unique($paths);
$paths = array_filter($paths);
cache_set($theme .':twig_paths', $paths);
return $templates;
}
/**
* Renders a system default template, which is essentially a PHP template.
*
* @param $template_file
* The filename of the template to render.
* @param $variables
* A keyed array of variables that will appear in the output.
*
* @return
* The output generated by the template.
*/
function twig_render_template($template_file, $variables) {
return \Drufony::service('twig')->render(basename($template_file), $variables);
}
/**
* Implements hook_extension().
*/
function twig_extension() {
return '.twig';
}