This project is not covered by Drupal’s security advisory policy.

Enables a themer to generate a CSS file while using PHP.

This module will go through all CSS files and replaces any file ending in '.php'
with a generated static CSS file that is uniquely identified by its last change
date and the dcss_vars() values. This allows the dynamic CSS file to be
aggregated as normal.

When generating dynamic CSS you always have to ensure the uniqueness of the
dynamically generated file. Always preset your variables through either your
theme's .info file or by invoking dcss_set().

A 'dcss' variable is included separate from the
'theme__settings' variable to improve the 'everything-in-code'
development method. Whenever you want your users to override variables, store
the values in 'dcss' so you can continue to deploy updates to the default
settings through your theme's .info file without reverting their overrides.

Due to the way Drupal handles a theme's settings, you must run the command
'drush dcss reset' after updating any dcss default variables and deploying new
code in order to ensure your new default theme settings are updated properly.

Example

Add the dynamic CSS file to your theme just like a normal CSS file:

  stylesheets[all][] = css/my-custom-styles.css.php

Your stylesheet can now contain PHP code:

  body {
    background-color: <?php print 'red'; ?>;
  }

Set default dynamic CSS variables in your theme's .info file:

  settings[dcss][background-color] = #f00
  settings[dcss][font-family-sans-serif] = Helvetica, Arial, Tahoma, sans-serif
  settings[dcss][font-family-headers] = Constantia, Lucida, Georgia, serif
  settings[dcss][font-m] = 1em

Recall dynamic CSS variables utilizing dcss():

  body {
    background-color: <?php print dcss('background-color'); ?>;
    font-family: <?php print dcss('font-family-sans-serif'); ?>;
    font-size: <?php print dcss('font-m'); ?>;
  }

  h1, h2, h3 {
    font-family: <?php print dcss('font-family-headers'); ?>;
  }

Any settings that are modified in a theme's .info file will not be made
immediately available as the default setting. In order make them immediately
available, execute the following drush command:

  drush dcss reset

Some fun methods dcss allows you to utilize in your css.php files:

dcss_url: Return the path of the original theme folder (since sites/default/files/dcss is generated, but assets need to be referenced from their original folders)

dcss_url($orig_url, $this_theme)

dcss_calc: Performs math on two values (e.g. will remove suffix, perform math, then reapply suffix)

dcss_calc($val1, $val2, $operator)

dcss_color: Allows you to alter a color by shade (behavior) or color relationship. If depth is set (fg or bg), it will make sure that a foreground color is always visible.

dcss_color($color, $behavior='0', $depth='bg', $default=NULL, $relationship=NULL, $relationship_phase=1)

dcss_opposite: Returns the opposite value of whatever is passed in (left, right, top, bottom)

dcss_opposite($value)

dcss_group: If you define a group of selectors as a variable (e.g. #main .class, #main .classtwo), it will allow you to append/prepend values to each member of the group (e.g. #main before, :hover after)

dcss_group($selectors, $prefix=NULL, $suffix=NULL, $postprefix=NULL, $postsuffix=NULL)




Some fun methods that will allow you to produce cross-browser (progressively-enhanced) implementations of CSS3 properties:

dcss_curve: Apply cross-browser compatible border-radius

function dcss_curve($curve)

dcss_boxshadow: (TODO: Needs to be implemented)

dcss_boxshadow($shadow)

dcss_gradient: Apply cross-browser gradients (TODO: Implement gradient type)

dcss_gradient($start_color, $end_color, $direction='top', $gradient_type='linear')

Credits

  • ceardach works on the backend implementation
  • danmasq contributes the CSS developer experience methods

Sponsorship

The development of this module has been sponsored by GoingOn in order to provide better systems for creating education sites in Drupal.

Note:

The user ceardach is no longer available. Please contact hefox if you need assistance.

Project information

Releases