2014-04-05, 01:06:25
SCSS plugin:
This plugin helps you to use SCSS to write your style sheets instead of CSS.
(see http://leafo.net/scssphp/ for information on the compiler and here for the syntax of SCSS)
The performance impact is minimal, as CSS files are generated when first needed and afterwards served directly to the site user.
Just write a SCSS file (e.g. background.scss here with a parameter color) in your template directory:
Of course your file will probably be longer and use each parameter multiple times.
Then you can use this file within your template:
API:
Compiles a SCSS file to a CSS file, if the SCSS file is newer or the parameters have changed ($multipleCSS = false).
Compiles a SCSS file to a parameter specific CSS file, if the SCSS file is newer ($multipleCSS = true).
The first parameter is the name of the SCSS file, e.g. "default.scss" (if it's directly in the theme directory) or "css/default.scss".
The second parameter is an associative array with the parameters for the SCSS file and the last parameter must be true, if for each parameter set a new CSS file should be compiled and all these CSS files should be available at the same time.
Returns the full URL of the generated CSS file.
The same as above but outputs the CSS file URL.
For yet another CSS like syntax see the Less plugin.
This plugin helps you to use SCSS to write your style sheets instead of CSS.
(see http://leafo.net/scssphp/ for information on the compiler and here for the syntax of SCSS)
The performance impact is minimal, as CSS files are generated when first needed and afterwards served directly to the site user.
Just write a SCSS file (e.g. background.scss here with a parameter color) in your template directory:
Code:
body { background-color: param(color); }
Then you can use this file within your template:
- Either your SCSS file is recompiled every time it or the parameters change, which makes sense, if you want to keep your CSS file untouched and just set the variables in your template file (or from some other site-wide setting):
Code:
<link rel="stylesheet" type="text/css" href="<?php get_scss_css('background.scss', array('color'=>'green')); ?>" />
- Or you want to set the parameters depending on the page (or time of date, etc.), thus using multiple CSS files generated from one SCSS file at the same time. The following example shows, how to set the background color based on a custom field color in the page (white as default, note the last parameter true):
Code:
<link rel="stylesheet" type="text/css" href="<?php get_scss_css('background.scss', array('color'=>return_custom_field('color', 'white')), true); ?>" />
API:
Code:
function return_scss_css($themeRelativeScssFile, $params=null, $multipleCSS=false)
Compiles a SCSS file to a parameter specific CSS file, if the SCSS file is newer ($multipleCSS = true).
The first parameter is the name of the SCSS file, e.g. "default.scss" (if it's directly in the theme directory) or "css/default.scss".
The second parameter is an associative array with the parameters for the SCSS file and the last parameter must be true, if for each parameter set a new CSS file should be compiled and all these CSS files should be available at the same time.
Returns the full URL of the generated CSS file.
Code:
function get_scss_css($themeRelativeScssFile, $params=null, $multipleCSS=false) {
For yet another CSS like syntax see the Less plugin.