$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(); ?>