我正在使用scssPHP来查看是否可以使用它来更改在现有的scss中设置的变量,因此我设置了一个测试用例:
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;
我的test.scss看起来像:
$color: red;
body {
background: $color;
}
现在我希望我可以在$PHP中将$color更改为blue,然后进行编译,并且我确定上面显示的方式不正确.
但是,有一种方法可以将$color的变量更改为blue,而不是重新编译test.scss?
解决方法:
我自己用完美无缺的解决方法来回答这个问题.
我用所有变量创建了一个config.scss.并决定在编译导入config.scss的layout.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();
}