Theming

Underscore.js in a Theme or Module for Drupal 8, 9

Last updated January 26, 2023
Categories
Up-to-date with minor version
8.9.x/9.4.x

Check your version

This tutorial covers a topic in Drupal 9 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 9, but we consider it archived.

Alternate resources

See the related change record for information on how to update your Underscore code with vanilla JS.

Underscore.js is a very small library which provides several utility functions and helpers to make working with JavaScript a little bit easier. In this tutorial we'll take a look at a part of the library, learn where the full library is documented, and see how we can make use of Underscore.js in a custom block on our Drupal site.

Theming Drupal Sites