Module Development

Movie Project: Create a Render Array and Theme Functions for Drupal 7

This page is archived

We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.

Display custom content using a render array.

Goal

Output custom data from a module using a theme function, render array, and template file.

Prerequisites

You will need the following knowledge and skills. If you need a review, check out the Additional resources section at the bottom of this page.

  1. Have a page return custom content.
  2. Create a render array.
  3. Register and create theme functions.

Tasks

Create a menu hook to link to a callback which will contain the render array. The callback function should be in a new file.

Return a render array from the function with test content.

Register and call a theme function to display the user's favorite film.

Register and call a theme function for the favorite film component. Use a template file to display the components of the content.

Recap

  • Custom pages can be created and returned by creating a render array.
  • Custom theme functions can be registered in a custom module, using theme functions to contain markup, or template files to create markup.

Further your understanding

Additional resources

Creative Commons License

Drupal Training Resources by Damian Robinson are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on a work at http://www.damianrobinson.co.uk.

Hands-On Exercises: Movie Project