View Mode Page Module

Out of the box, Drupal ships with two view modes: full and teaser. If you're not familiar with these, they are essentially a means for site builders to change the display of a node. Modules like Display Suite also extend this functionality by adding the ability to create new view modes. This opens up many powerful options for how to create and manage the display of your content.

While we could create new view modes for pages, we often found we wanted the same node to have "multiple URLs", but with different fields. This included showing an about page or other related content that was part of a single node. For a content creator it made the most sense to tie this in directly to a given node, instead of related nodes, but this didn't really help us when it came to display this on the front end.

At first, we thought we would just create a module that added a page for a specific field. But this would be pretty limited and not as powerful as harnessing view modes. The new module we created, View Mode Page module, allows you to create a URL pattern that displays a node with a specific view mode.

As an example, assume we have a "project" content type that includes:

  • A title
  • Description
  • About the project
  • Links related to the project

With View Mode Page, we can assign a URL pattern that can display the about text as its own page. To do this, you go to the "manage display" tab for a content type, and then open the "View mode page" tab. You can assign a pattern with one or more wildcards like project/%/about. You can then configure the view mode display to just output the about field or a combination of fields. This creates a simple means for your content creators to manage the details of a node but gives site builders the ability to organize those details on the site. And if your specs for that page change, it's easy to change the configuration on the node's "manage display" page.

Code Drupal Drupal Planet

Read This Next