From: Eduardo Date: Sat, 11 Nov 2023 16:11:50 +0000 (+0100) Subject: do not edit the file, just return the file with the var set X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=7855bad641ce2e79f937274462ef716e55bcd607;p=thericegoat.com.git do not edit the file, just return the file with the var set --- diff --git a/page-generator/generator.php b/page-generator/generator.php index abaf483..928fa50 100644 --- a/page-generator/generator.php +++ b/page-generator/generator.php @@ -77,15 +77,16 @@ class CodeGenerator } /** - * Replace a template variable with a given value + * Replace a template variable with a given value and return the new content string */ function setTemplateVar(string $filePath, string $var, string $value) { $replaceVar = "$$" . $var . "$$"; - $content = file_get_contents($filePath); - $content = str_replace($replaceVar, $value, $content); - file_put_contents($filePath, $content, LOCK_EX); + if (file_exists($filePath)) + return str_replace($replaceVar, $value, file_get_contents($filePath)); + else + return str_replace($replaceVar, $value, $filePath); } /**