A temporary file is created if it does not already exists.
function(string $st)
{
if (\defined('BBN_DATA_PATH')) {
$dir = File\Dir::createPath(BBN_DATA_PATH.'tmp/bbn-templates');
}
else {
$dir = File\Dir::createPath(sys_get_temp_dir().'/bbn-templates');
}
if (!$dir) {
throw new \Exception(X::_("Impossible to create the template directory"));
}
$md5 = md5($st);
$file = $dir.'/tpl.'.$md5.'.php';
if (!file_exists($file)) {
$tpl = LightnCandy::compile(
$st,
[
'flags' => LightnCandy::FLAG_MUSTACHELOOKUP |
LightnCandy::FLAG_PARENT |
LightnCandy::FLAG_HANDLEBARSJS |
LightnCandy::FLAG_ERROR_LOG
]
);
file_put_contents($file, '');
}
return include($file);
}