1

我在我的 Joomla 网站中使用lessphp,我正在构建一个模板,我想设置一些变量并在一个更少的文件中使用它们,为此我正在使用类 autoCompileLess 但我得到了错误

无法解析传入的变量@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 文件编译正确,所以我不明白为什么会出现这个错误。有人可以给我建议吗?谢谢你们!

4

1 回答 1

2

看来您没有在函数中设置变量 $fontname 和 $bfontname 。

于 2017-02-07T16:27:52.067 回答