drupal_add_css

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE)
drupal7 drupal_add_css($data = NULL, $options = NULL)

Adds a CSS file to the stylesheet queue.

Übergabeparameter

$path (optional) The path to the CSS file relative to the base_path(), e.g., modules/devel/devel.css.

Modules should always prefix the names of their CSS files with the module name, for example: system-menus.css rather than simply menus.css. Themes can override module-supplied CSS files based on their filenames, and this prefixing helps prevent confusing name collisions for theme developers. See drupal_get_css where the overrides are performed.

If the direction of the current language is right-to-left (Hebrew, Arabic, etc.), the function will also look for an RTL CSS file and append it to the list. The name of this file should have an '-rtl.css' suffix. For example a CSS file called 'name.css' will have a 'name-rtl.css' file added to the list, if exists in the same directory. This CSS file should contain overrides for properties which should be reversed or otherwise different in a right-to-left display.

$type (optional) The type of stylesheet that is being added. Types are: module or theme.

$media (optional) The media type for the stylesheet, e.g., all, print, screen.

$preprocess (optional) Should this CSS file be aggregated and compressed if this feature has been turned on under the performance section?

What does this actually mean? CSS preprocessing is the process of aggregating a bunch of separate CSS files into one file that is then compressed by removing all extraneous white space.

The reason for merging the CSS files is outlined quite thoroughly here: http://www.die.net/musings/page_load_time/ "Load fewer external objects. Due to request overhead, one bigger file just loads faster than two smaller ones half its size."

However, you should *not* preprocess every file as this can lead to redundant caches. You should set $preprocess = FALSE when:

  • Your styles are only used rarely on the site. This could be a special admin page, the homepage, or a handful of pages that does not represent the majority of the pages on your site.

Typical candidates for caching are for example styles for nodes across the site, or used in the theme.

Rückgabewert

An array of CSS files.

▾ 28 functions call drupal_add_css()

aggregator_init in modules/aggregator/aggregator.module
Implementation of hook_init().
block_admin_display_form in modules/block/block.admin.inc
Generate main blocks administration form.
book_init in modules/book/book.module
Implementation of hook_init(). Add's the book module's CSS.
color_scheme_form in modules/color/color.module
Form callback. Returns the configuration form.
comment_render in modules/comment/comment.module
Renders comment(s).
dblog_init in modules/dblog/dblog.module
drupal_get_css in includes/common.inc
Returns a themed representation of all stylesheets that should be attached to the page.
forum_init in modules/forum/forum.module
Implementation of hook_init().
help_main in modules/help/help.admin.inc
Menu callback; prints a page listing a glossary of Drupal terminology.
hook_init in developer-docs/hooks/core.php
Perform setup tasks. See also, hook_boot.
node_init in modules/node/node.module
Implementation of hook_init().
openid_form_alter in modules/openid/openid.module
Implementation of hook_form_alter : adds OpenID login to the login forms.
openid_user_identities in modules/openid/openid.pages.inc
Menu callback; Manage OpenID identities for the specified user.
poll_init in modules/poll/poll.module
Implementation of hook_init().
search_form in modules/search/search.module
Render a search form.
system_init in modules/system/system.module
Implementation of hook_init().
template_preprocess_maintenance_page in includes/theme.maintenance.inc
The variables generated here is a mirror of template_preprocess_page(). This preprocessor will run it's course when theme_maintenance_page() is invoked. It is also used in theme_install_page() and theme_update_page() to keep all the variables…
template_preprocess_page in includes/theme.inc
Process variables for page.tpl.php
theme_color_scheme_form in modules/color/color.module
Theme color form.
theme_profile_admin_overview in modules/profile/profile.admin.inc
Theme the profile field overview into a drag and drop enabled table.
theme_taxonomy_overview_terms in modules/taxonomy/taxonomy.admin.inc
Theme the terms overview as a sortable list of terms.
theme_taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Render a taxonomy term page HTML output.
theme_update_report in modules/update/update.report.inc
Theme project status report.
tracker_page in modules/tracker/tracker.pages.inc
Menu callback. Prints a listing of active nodes on the site.
user_init in modules/user/user.module
Implementation of hook_init().
_drupal_maintenance_theme in includes/theme.maintenance.inc
Sets up the theming system for site installs, updates and when the site is in off-line mode. It also applies when the database is unavailable.
_init_theme in includes/theme.inc
Initialize the theme system given already loaded information. This function is useful to initialize a theme when no database is present.
_locale_translate_language_list in includes/locale.inc
List languages in search result table

Code

includes/common.inc, line 1794

<?php
function drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE) {
  static $css = array();
  global $language;

  // Create an array of CSS files for each media type first, since each type needs to be served
  // to the browser differently.
  if (isset($path)) {
    // This check is necessary to ensure proper cascading of styles and is faster than an asort().
    if (!isset($css[$media])) {
      $css[$media] = array('module' => array(), 'theme' => array());
    }
    $css[$media][$type][$path] = $preprocess;

    // If the current language is RTL, add the CSS file with RTL overrides.
    if ($language->direction == LANGUAGE_RTL) {
      $rtl_path = str_replace('.css', '-rtl.css', $path);
      if (file_exists($rtl_path)) {
        $css[$media][$type][$rtl_path] = $preprocess;
      }
    }
  }

  return $css;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen