Module Development

Output a List of Items for Drupal 8, 9, and 10

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.

Drupal Module Development