1

I'm using lessphp in my Joomla website, I'm building a template, I'd like to set some variables and use them in a less file, to do that I'm using the class autoCompileLess but I'm getting the error

failed to parse passed in variable @font:

This is my lessphp code:



    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');


Although if I check the output.css file I can see my .less file compiled correctly so I don't get why I'm getting this error. Someone could advice me? Thank you all!

valentina.a87
  • 117
  • 1
  • 3
  • 15

1 Answers1

2

It seems you didn't set the vars $fontname and $bfontname in your function.

Salagir
  • 21
  • 3