cssphp is a cool tools to compile SCSS file in PHP.
SCSS is a CSS preprocessor language that adds many features like variables, mixins, imports, nesting, color manipulation, functions, and control directives.
scssphp is ready for inclusion in any project. It includes a command-line tool for running the compiler from a terminal/shell or script.
How to use it:
use the composer.json and add the following code
1 2 3 4 5 6 7 8 9 | { "require": { "scssphp/scssphp": "1.2" } } |
then in the php file, add the following code to compile the sass fie
dd
1 2 3 4 5 6 7 8 9 10 11 12 13 | require_once "scssphp/scss.inc.php"; use ScssPhp\ScssPhp\Compiler; $scss = new Compiler(); echo $scss->compile(' $color: #abc; div { color: lighten($color, 20%); } '); |
For a variable, you can add the setVariables function:
1 2 3 4 5 6 7 8 9 10 11 12 | use ScssPhp\ScssPhp\Compiler; $scss = new Compiler(); $scss->setVariables(array( 'red' => 'false', )); $sassfile="/path/to/scss/file"; echo $scss->compile($sassfile); |