CodeFox's avatar

Compiling user-generated assets on demand

Hi,

I'm currently working on something which lets a theme be uploaded and then let a user customise aspects of that theme via a form.

Right now the theme CSS files are being uploaded to S3 and served from a CDN. Certain variables are stored on a configuration page which then will post to a controller.

From that I want to be able to take the user input and pass the values to the relevant SCSS variable. Once that is done then I'll need to compile the SCSS and upload the new CSS file, replacing the old one.

I've been trying this with the scssphp package but haven't had much luck. I think mix may be a better way of doing this but wondered if anyone has any advice on how to achieve this?

Thanks!

0 likes
2 replies
CodeFox's avatar

Hey @D9705996 - I actually read that prior to starting this task and unfortunately I keep running into issues with scssphp, namely that it won't import my variable containing the values passed by the user.

As I understand it, the script requires that you pass a string to the compiler so have tried casting to a string with no luck. For example:

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

        $file = file_get_contents('site.com/my.scss');
        $output = $scss->compile('@import "'. $file .'";' . $statement);
            return $output;

This just returns my input SCSS file:

@import "$background_colour: 'red' $logo_url: 'https://test.com' .logo { background-image: url($logo_url); } .background_colour { background-color: $background_colour; } ";

Please or to participate in this conversation.