diff options
Diffstat (limited to 'php/templates.php')
| -rw-r--r-- | php/templates.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/php/templates.php b/php/templates.php new file mode 100644 index 0000000..4ead3f8 --- /dev/null +++ b/php/templates.php @@ -0,0 +1,20 @@ +<?php + +function render_component(string $componentPath): string { + ob_start(); + include($componentPath); + return ob_get_clean(); +} + +function template_process(string $template, array $components = []): string { + $html = file_get_contents($template); + + foreach ($components as $placeholder => $componentPath) { + $injectedContent = render_component($componentPath); + $html = str_replace($placeholder, $injectedContent, $html); + } + + return $html; +} + +?> |
