Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change scss variable with scssphp

Tags:

php

sass

I'm using scssphp to see if I can use it to change variables that are set in my existing scss so I've set up a testcase:

require_once "scssphp-0.1.7/scss.inc.php";

use Leafo\ScssPhp\Compiler;
use Leafo\ScssPhp\Server;

$scss = new Compiler();
$scss->addImportPath('testsass');

$scss->compile('$color: blue;');
$test = $scss->compile('@import "test.scss"');

echo $test;

My test.scss looks like:

$color: red;

body {
    background: $color;
}

Now I was hoping I could change $color to blue in my php and than compile it and I'm sure the way displayed above is not correct.

But is there a way to change the variable of $color to blue and than recompile my test.scss?

like image 620
CaptainCarl Avatar asked Mar 20 '26 00:03

CaptainCarl


1 Answers

Answering this myself with a workaround which works flawlessly. I've made a config.scss with all my variables in it. And decided to open and rewrite that before compiling my layout.scss which imports config.scss

require_once "scssphp-0.1.7/scss.inc.php";

use Leafo\ScssPhp\Compiler;
use Leafo\ScssPhp\Server;

$scss = new Compiler();
$scss->setImportPaths('sass');

//$txt = '$color: yellow;';
$txt = '$font: "Open sans";';
$txt .= '$body-font-size: 15px;';
$txt .= '$containerWidth: 1140px;';
$txt .= '$gutter-size: 15px;';
$txt .= '$primarycolor: red;';
$txt .= '$secondarycolor: blue;';
$txt .= '$background: #e8e3e3;';
$txt .= '$textcolor: $primarycolor;';
$txt .= '$linkcolor: #000;';

$file = fopen('sass/_configuratie.scss', "w");
if (fwrite($file, $txt)) {
    $server = new Server('sass', null, $scss);
    $server->serve();
} 
like image 84
CaptainCarl Avatar answered Mar 21 '26 12:03

CaptainCarl