. */ require_once ROOT . '/php/preprocess.php'; function replace(string $templatePath, array $replacements = []): string { $html = import($templatePath); foreach ($replacements as $placeholder => $replacementValue) { $replacementValue = tidy((string)$replacementValue); if ($replacementValue === '') { $pattern = '/^[ \t]*' . preg_quote($placeholder, '/') . '[ \t]*\n?/m'; $html = preg_replace($pattern, '', $html); } $pattern = '/^([ \t]*)' . preg_quote($placeholder, '/') . '/m'; $html = preg_replace_callback($pattern, function (array $match) use ($replacementValue) { return indent($replacementValue, $match[1]); }, $html); $html = str_replace($placeholder, $replacementValue, $html); } return tidy($html); } ?>