Output a List of Items for Drupal 8, Drupal 9

Last updated March 4, 2021
Module Development8.9.x/9.0.x

Drupal makes it easy to convert an array of strings to an ordered or unordered HTML list using '#theme' => 'item_list' elements in a render array. This is commonly done by module developers to display a list such as links to content, the values of settings in a module, or the names of everyone who has viewed a page. Displaying lists is a super common task for a content management system.

In this tutorial we'll look at:

  • Outputting an array of items as an unordered <ul> list
  • Properties specific to '#theme' => 'item_list' in a render array

By the end of this tutorial you should be able to output unordered lists.