Check your version

This tutorial covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Last updated June 7, 2017

Create a custom module and alter the content on a node page using a hook and existing theme functions.

Objectives and Prerequisites

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

  1. How to create a custom module.
  2. Understand how to add custom content to the "Movie Review" page.
  3. How to use existing theme functions to create markup.

Tasks

Create a custom module with info and module files.

Use hook_node_view to replace the default Genre taxonomy links with custom links on the Movie Review page. The URL format of the new links should be as follows: <a href="/reviews/[genre]">[genre]</a>.

The links should be in an unordered list.

Both the links and list should be themed using existing Drupal functions.

Summary

  • We can alter markup within a node page by using the node_view hook.
  • Markup should be generated only by existing theme functions where possible.

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.