$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_raw = \json_decode( \file_get_contents(__DIR__ . '/data.json'), true ); $data = [ 'title' => ($data_raw['title'] ?? 'Portal'), 'entries' => \array_map( fn($entry_raw) => [ 'active' => ($entry_raw['active'] ?? true), 'target' => ($entry_raw['target'] ?? '#'), 'label' => ($entry_raw['label'] ?? ''), 'image' => ($entry_raw['image'] ?? ''), 'open_in_new_tab' => ($entry_raw['open_in_new_tab'] ?? false), ], ($data_raw['entries'] ?? []), ), ]; print( template_render_by_name( 'main', [ 'title' => $data['title'], 'entries' => \implode( "\n", \array_map( fn($entry) => template_render_by_name( 'entry', [ 'a_href' => $entry['target'], 'a_target' => ($entry['open_in_new_tab'] ? '_blank' : '_self'), 'img_src' => $entry['image'], 'img_alt' => $entry['label'], 'label' => $entry['label'], ] ), \array_values(\array_filter( $data['entries'], fn($entry) => $entry['active'] )) ) ), ] ) ); } main(); ?>