Underscore.js

Component ID

1088584

Component name

Underscore.js

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

10482

Component created

Component changed

Component body

Provides Library API access to the Underscore.js JavaScript library.

Features (7.x-2.x)

  • Makes Underscore.js available to other modules and custom code via the Library API
  • Provides a drush command (underscore-download) to download and install the latest version of the library

Usage (7.x-2.x)

After enabling this module, install the Underscore.js JavaScript file:

  • Without drush: Download underscore.js and store it in your libraries directory. In most cases the resulting path should be sites/all/libraries/underscore/underscore.js
  • With drush: Run the command drush underscore-download

In your module code, add the library with libraries_load() and drupal_add_library(). If unsure where, add it in an implementation of hook_init(). Use 'underscore' for both the module and library name arguments, like this:

libraries_load('underscore');
drupal_add_library('underscore', 'underscore');

You can update your version of Underscore.js to the latest version by calling the drush command (drush underscore-download).

Upgrading from 7.x-1.x to 7.x-2.x

The 7.x-2.x branch is a rewrite of the existing module. Upgrading to the 7.x-2.x branch will require changes to your code. Notable changes to the module include:

  • The actual Underscore.js JavaScript is no longer bundled with this module. It must be downloaded and installed manually or with the drush command provided in this module.
  • The Underscore.js library is no longer enabled automatically. To use it, your code must call libraries_load() and drupal_add_library(). An example is provided in the section above.
  • Now uses the library hooks provided by Libraries API module (rather than hook_library() from core).