-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
94 lines (85 loc) · 3.01 KB
/
index.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
@include_once __DIR__ . '/vendor/autoload.php';
Kirby::plugin('bnomei/handlebars', [
'options' => [
'component' => true,
'compile-flags' => function () {
// https://zordius.github.io/HandlebarsCookbook/9900-lc-options.html
return \LightnCandy\LightnCandy::FLAG_ELSE
| \LightnCandy\LightnCandy::FLAG_NOESCAPE
// | \LightnCandy\LightnCandy::FLAG_PARENT
// | \LightnCandy\LightnCandy::FLAG_RUNTIMEPARTIAL
// | \LightnCandy\LightnCandy::FLAG_NAMEDARG
;
},
'dir-templates' => function () {
return kirby()->roots()->templates();
},
'dir-partials' => function () {
$templates = option('bnomei.handlebars.dir-templates');
if (is_callable($templates)) {
$templates = $templates();
}
return $templates . DIRECTORY_SEPARATOR . 'partials';
},
'extension-input' => 'hbs', // or 'mustache' etc.
'extension-output' => 'lnc',
'extension-kql' => 'json',
// ALLOW creation...
'cache' => true, // to get the root folder
'cache.render' => true, // creates a plugin cache called 'render'
'cache.files' => true, // creates a plugin cache called 'files'
'cache.lnc' => true, // creates a plugin cache called 'lnc'
// actually used config
'render' => false,
'files' => true,
'lnc' => true,
'queries' => [
'site.title',
'site.url',
'page.autoid',
'page.title',
'page.text',
'page.url',
'page.slug',
'page.template',
],
],
'components' => [
'template' => function (Kirby\Cms\App $kirby, string $name, string $type = 'html', string $defaultType = 'html') {
if (option('bnomei.handlebars.component')) {
return new Bnomei\HandlebarsTemplate($name, $type);
}
return new Kirby\Cms\Template($name, $type);
},
],
'snippets' => [
'handlebars/render' => __DIR__ . '/snippets/handlebars/render.php',
],
'pageMethods' => [
'handlebars' => function ($template = null, $data = []) {
return (new \Bnomei\Handlebars())->render(
$template ?? $this->template(),
$this->controller($data),
null,
null,
true
);
},
],
]);
if (!class_exists('Bnomei\Handlebars')) {
require_once __DIR__ . '/classes/Handlebars.php';
}
if (!function_exists('handlebars')) {
function handlebars(string $template, $data = [], $return = false): ?string
{
return (new \Bnomei\Handlebars())->render($template, $data, null, null, $return);
}
}
if (!function_exists('hbs')) {
function hbs(string $template, $data = [], $return = false): ?string
{
return (new \Bnomei\Handlebars())->render($template, $data, null, null, $return);
}
}