Module Development

Output Content Using Render API for Drupal 8, 9, and 10

Controllers in Drupal should return renderable arrays that contain the content to display for the page. Doing so makes it easier for the theme layer to override the output and customize it for a specific site.

In this tutorial, we'll:

  • Convert the WeatherPage controller to use a renderable array instead of hard-coded HTML for displaying the weather forecast.
  • Verify our updates.

By the end of this tutorial, you should understand how to structure content as a render array within a controller.

Drupal Module Developer Guide