by Jeff Eaton

Module Monday: Entity View Modes

Drupal offers a few standard ways of displaying all content: the shortened teaser view is often used on listing pages, and the full default view is always used when visitors hit a node's canonical URL. Customizing the output of these view modes is easy, and modules that display content usually let site builders choose which view mode should be used when outputing them. Unfortunately, Drupal core can't help if you need more than the basics -- say, a 'summary' view mode for nodes, or and 'author info' view mode user accounts. That's where the Entity View Modes module comes in: it makes creating and managing custom view modes easy.

Admin interface screenshot

Once installed, Entity View Modes provides an overview page listing every viewable entity currently installed. Nodes, comments, taxonomy terms, and user accounts are all supported with a standard install of Drupal core. For each "bundle" in an entity type (like Articles and Pages for nodes), administrators can see the existing view modes and add new ones. Once created, these view modes appear on the Content Type Display Settings page. Administrators can assign which fields and formatters are used in those view modes, just like the standard Teaser and Default modes.

From that point on, the new custom view modes should be available in most places that content is displayed. The most common use is when building new content listings with the Views module. Rather than meticulously picking each field that should appear in a Gallery View, then theming it by hand, you can create a "Gallery" mode for your content. The View itself can simply print out the content in "Gallery" mode, simplifying theming and making it easier to re-use.

Screenshot of module in action

There's not much complain about with Entity View Modes -- it even allows you to use custom theme templates for each view mode if you need full control. (The node--article.tpl template can be overridden by node--article--gallery.tpl, for example.) It's a simple way to define reusable presentation variations for each content type, and it's a common part of our site-building toolbox.