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?
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With