portal/source/index.html.php
2024-06-02 11:56:52 +02:00

78 lines
1.1 KiB
PHP

<?php
/**
*/
function string_coin(
string $template,
array $arguments
) : string
{
$result = $template;
foreach ($arguments as $key => $value) {
$result = \str_replace(\sprintf('{{%s}}', $key), $value, $result);
}
return $result;
}
/**
*/
function template_render_by_name(
string $template_name,
array $arguments
) : string
{
return string_coin(
\file_get_contents(
string_coin(
'{{directory}}/templates/{{name}}.html.tpl',
[
'directory' => __DIR__,
'name' => $template_name,
]
)
),
$arguments
);
}
/**
*/
function main(
) : void
{
$data = \json_decode(
\file_get_contents(__DIR__ . '/data.json'),
true
);
print(
template_render_by_name(
'main',
[
'title' => $data['title'],
'entries' => \implode(
"\n",
\array_map(
fn($entry) => template_render_by_name(
'entry',
[
'label' => $entry['label'],
'target' => $entry['target'],
'image' => $entry['image'],
]
),
\array_values(\array_filter(
$data['entries'],
fn($entry) => ($entry['active'] ?? true)
))
)
),
]
)
);
}
main();
?>