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!

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

WordPress version 6.4

I resolved this error by doing this.
The Cherry theme version is 3.1.5 ( as the client told that he had not updated the theme since 2014)

Step 1 (fix the file issues)

wp-content/themes/CherryFramework/includes/lessc.inc.php

Step 2 (fix the file issues)

wp-content/themes/CherryFramework/includes/less-compile.php

On line 157, you see following code

        try {
                $less->compileFile($inputFile, $outputFile);
        } catch (Exception $ex) {
                echo "lessphp fatal error: ".$ex->getMessage();
        }

Replace ith with

        try {
                $less->compileFile($inputFile, $outputFile);
        } catch (Exception $ex) {
                # echo "lessphp fatal error: ".$ex->getMessage();
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.