-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionsAPI.php
43 lines (36 loc) · 1.09 KB
/
FunctionsAPI.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
<?php
namespace ProcessWire;
/**
*
*/
function component(string $component, array $params = [], array $attrs = []): string {
return wire('component')->render($component, $params, $attrs);
}
function getComponentTemplate(string $dir, string $template = ''): string {
$explode = explode(DIRECTORY_SEPARATOR, dirname($dir));
$component = end($explode);
$templatesPath = wire('config')->paths->templates . 'components/templates';
$tpl = '';
if ($template) {
$paths = [
"{$templatesPath}/{$component}/template-{$template}.php",
"{$templatesPath}/{$component}-{$template}.php",
"{$dir}/template-{$template}.php",
];
} else {
$paths = [
"{$templatesPath}/{$component}/template-default.php",
"{$templatesPath}/{$component}-default.php",
];
}
$paths[] = "{$dir}/template-default.php";
foreach ($paths as $filename) {
if ($tpl) {
continue;
}
if (file_exists($filename)) {
$tpl = $filename;
}
}
return $tpl;
}