}
/**
- * 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);
}
/**