drupal_load_stylesheet

Versions
6 – 7
drupal_load_stylesheet($file, $optimize = NULL)

Loads the stylesheet and resolves all @import commands.

Loads a stylesheet and replaces @import commands with the contents of the imported file. Use this instead of file_get_contents when processing stylesheets.

The returned contents are compressed removing white space and comments only when CSS aggregation is enabled. This optimization will not apply for color.module enabled themes with CSS aggregation turned off.

Parameters

$file Name of the stylesheet to be processed.

$optimize Defines if CSS contents should be compressed or not.

Return value

Contents of the stylesheet, including any resolved @import commands.

▾ 3 functions call drupal_load_stylesheet()

color_scheme_form_submit in modules/color/color.module
Submit handler for color change form.
drupal_build_css_cache in includes/common.inc
Aggregate and optimize CSS files, putting them in the files directory.
_drupal_load_stylesheet in includes/common.inc
Loads stylesheets recursively and returns contents with corrected paths.

Code

includes/common.inc, line 3437

<?php
function drupal_load_stylesheet($file, $optimize = NULL) {
  // $_optimize does not use drupal_static as it is set by $optimize.
  static $_optimize;
  // Store optimization parameter for preg_replace_callback with nested @import loops.
  if (isset($optimize)) {
    $_optimize = $optimize;
  }

  $contents = '';
  if (file_exists($file)) {
    // Load the local CSS stylesheet.
    $contents = file_get_contents($file);

    // Change to the current stylesheet's directory.
    $cwd = getcwd();
    chdir(dirname($file));

    // Process the stylesheet.
    $contents = drupal_load_stylesheet_content($contents, $_optimize);

    // Change back directory.
    chdir($cwd);
  }

  return $contents;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.