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

Last updated January 26, 2023
Up-to-date with minor version

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.

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