forked from amteich/kirby-twig
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
45 lines (37 loc) · 1.48 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
<?php
@include_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/src/helpers.php';
use Kirby\Cms\App;
use Kirby\Template\Snippet;
Kirby::plugin('wearejust/twig', [
'options' => [
'usephp' => true
],
'components' => [
'template' => function (App $kirby, string $name, string $contentType = 'html', string $defaultType = 'html') {
return new Wearejust\Kirby\Twig\Template($name, $contentType, $defaultType);
},
'snippet' => function (Kirby $kirby, string $name, array $data = [], bool $slots = false) {
$snippets = A::wrap($name);
foreach ($snippets as $name) {
$name = (string)$name;
$file = $kirby->root('snippets') . '/' . $name . '.php';
if (file_exists($file) === false) {
$file = $kirby->root('snippets') . '/' . $name . '.twig';
if (file_exists($file)) {
return twig('@snippets/' . $name . '.twig', $data);
} else {
$file = $kirby->extensions('snippets')[$name] ?? null;
if (null !== $file && Str::endsWith(strtolower($file), '.twig')) {
return twig($name . '.twig', $data);
}
}
}
if ($file) {
break;
}
}
return Snippet::factory($name, $data, $slots);
}
]
]);