Combining SCSS and PHP
-
Some time ago I started working with SASS (scss) and soon after that I started using an ‘external’ _config.scss file in which I declare all default variables which are being used in the rest of the stylesheets. That way I have only one place to deal with changes of color. margins etc.
Example:// colors $primary-color: #00baf1; $secondary-color: #f9a533; $white: #ffffff; $black: #000000; // Calculate alternative colors $primary-color-alt: lighten($primary-color, 15%); $secondary-color-alt: lighten($secondary-color, 15%); // Calculate grey shades $lightgrey: mix($white, $black, 80%); $grey: mix($white, $black, 50%); $darkgrey: mix($white, $black, 20%); // Layout $default-margin: 20px;
Etc.
This works great for me.However…
I’m also often using the WP customizer API (WP_Customize_Control)
And there I also make use of default settings. These can be declared in the functions file. So I have some defaults in _config.scss and other defaults in customizer_functions.php.What I’m looking for is a way to connect these two. So that I have one place where both defaults are being managed. And that, as an example, I could change the default border color once. And that the stylesheets, as well as the WP Customizer us that one value as their default.
The only thing I could think of was creating a default ‘style_defaults.php’ file (with header “Content-type: text/css”) in which I do the magic. So I can easily include / import it in other PHP or CSS files.
This works as long as I’m using plain CSS. But SASS throws errors when I do something like:
$primary-color = '#00baf1'; echo '$primary-color: ' . $primary-color; // in order to parse scss: $primary-color: #00baf1;
So this won’t help me when using SCSS.
I’m not only looking for tips on how to achieve this, but I’m also interested in any other thoughts, like why this may be a bad idea to do, or other ways to achieve the same thing.
- The topic ‘Combining SCSS and PHP’ is closed to new replies.