roo
roo

Reputation: 343

How to compile SCSS with scssphp

I'm currently trying to compile some SCSS which I'm receiving via a form request. The current workflow is that the user submits form data as follows:

{"$background_color":"#f3f3f3","$logo_url":"https:\/\/logo.co\/random"}

I then transform this input to the following:

$background_color: '#f3f3f3'; $logo_url: 'https://logo.co/random'

This should be valid for the purposes of compiling it to CSS so I run it through SCSSPHP with the following:

$scss->addImportPath(Storage::disk('tmp')); $output = $scss->compile("@import 'test'; $statement ");

No errors are triggered when I run this and the output is:

@import 'test';

My test.scss is as follows:

$background_colour: 'red'
$logo_url: 'https://test.com'

.logo {
  background-image: $logo_url;
}

.background_colour {
    background-colour: $background_colour;
}

What am I doing wrong here?

Upvotes: 0

Views: 3416

Answers (1)

Wimanicesir
Wimanicesir

Reputation: 5122

The problem is that you're not passing a string to this function. Parse your scss as a string by using the function file_get_contents

require_once "scssphp/scss.inc.php";

use Leafo\ScssPhp\Compiler;

$scss = new Compiler();

// Gets the content of the scss file in string format

$scss_string = file_get_contents(path/to/scss.file);

echo $scss->compile($scss_string);

Upvotes: 1

Related Questions