portal/index.html.php

61 lines
902 B
PHP
Raw Normal View History

2024-06-01 18:53:24 +02:00
<?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(\sprintf('%s/%s.html.tpl', __DIR__, $template_name)),
$arguments
);
}
function main(
) : void
{
$data = \json_decode(
\file_get_contents('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'],
]
),
$data['entries']
)
),
]
)
);
}
main();
?>