php - lessphp 解析传入变量错误失败

标签 php css joomla less lessphp

我在我的 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/

相关文章:

php - Yii 中的动态渲染

php - 获取不在内容中的图像高度

jquery - 单击正文 html 时隐藏元素

php - joomla:使用 joomla db 函数在 joomla 外部建立数据库连接

joomla - joomla 面包屑如何在内部工作?

php - 从php函数中的选择查询中获取结果

php - 如何使用 Highcharts 导出整个页面或 html 内容而不仅仅是图表?

css - 如何让 Scroll 在 Firefox 中可见

java - 如何避免在 Struts 中生成更多的 HTML 元素

php - 在网页中打开网页