我在我的 Joomla 网站上使用 lessphp,我正在构建一个模板,我想设置一些变量并在一个 less 文件中使用它们,为此我正在使用类 autoCompileLess 但我得到错误
failed to parse passed in variable @font:
这是我的 lessphp 代码:
require_once "lessc.inc.php";
$less = new lessc;
//$css_print .= $less->compile("body {font-family: @bfont;} .vikqt_box {font-family:@font;}");
// create a new cache object, and compile
function autoCompileLess($inputFile, $outputFile) {
// load the cache
$cacheFile = $inputFile.".cache";
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $inputFile;
}
$less = new lessc;
$less->setVariables(array(
"font" => $fontname,
"bfont" => $bfontname
));
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
file_put_contents($cacheFile, serialize($newCache));
file_put_contents($outputFile, $newCache['compiled']);
}
}
autoCompileLess(JPATH_SITE.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$this->template.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.less', JPATH_SITE.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$this->template.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'output.css');
虽然如果我检查 output.css 文件,我可以看到我的 .less 文件被正确编译,所以我不明白为什么我会收到这个错误。 有人可以建议我吗? 谢谢大家!
最佳答案
您似乎没有在函数中设置变量 $fontname 和 $bfontname。
关于php - lessphp 解析传入变量错误失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39488096/