How a node is displayed depends on the context in which it is viewed, such as the difference between full nodes and teasers. On the page for field display management there are extra settings under the label custom display settings. The settings consist of a check box list of all view modes available for nodes, marking which view modes should have customized display settings. In a standard Drupal installation only teaser is checked, resulting in two sub tabs on the manage display page – default and teaser. The sub tabs lead to separate settings for each view mode.

In a standard Drupal installation, the following view modes are available (machine names in parentheses):

  • Full content (full): This is normally used only when visiting the URL for a particular node.
  • Teaser (teaser): This is used on two list types – the front page and taxonomy term lists.
  • RSS (rss): These settings are used when including the node in RSS feeds.
  • Search index (search_index): This is used when Drupal core's Search module indexes content on the site. Fields that are hidden in this view mode will not be searchable.
  • Search result (search_result): This is used when presenting search results on the website with Drupal core's Search module.

While nodes have a number of different view modes, other entities only have one view mode each. They are full comment (comments), user account (users) and taxonomy term page (taxonomy terms).

All entities have their own pages for managing field display. They are accessed as a tab from the pages used for managing their field settings.

In Drupal 7, additional View modes can be added to entities using hook_entity_info_alter().

Example Code:

/**
 * Implements hook_entity_info_alter().
 */
function MYMODULE_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['alternate'] = array(
    'label' => t('Alternate'),
    'custom settings' => TRUE,
  );
}

In Drupal 8, adding a custom view mode can be accomplished without code. To add one, expand Custom Display Settings on the Manage Display tab of a content type, then click Manage View Modes.

Each view mode can have a separate template. A template for an article node (machine name: article) is defined as node--article.tpl.php, then a template such as node--article--teaser.tpl.php can be defined specific for the teaser view mode. By adding more view modes the same piece of content can be re-used in other places with different markup and selected fields. To allow for templates per view mode just create a template suggestion in THEME_preprocess_node:

/**
 * Implements template_preprocess_node()
 */
function THEME_preprocess_node(&$variables) {
  $node = $variables['node'];
  $view_mode = $variables['view_mode'];
  
  // Set up template suggestions for non-standard view modes
  if ($view_mode !== 'full') {
    $variables['theme_hook_suggestions'][] = 'node__' . $node->type . '__' . $view_mode;
  }
}

Contributed modules can be leveraged to add View modes to entities via the UI without writing code.

Display Suite

The Display Suite module makes it possible to add more view modes to your entities.

Entity View Modes

The Drupal 7 successor to Build modes which will allow administrators to define custom view modes for entities.

AttachmentSize
view_modes_1.png50.58 KB

Comments

candelas’s picture

there is a very good module: Entity view modes

//trying to answer one question for each one that i make.
//this way, drupal will be more friendly and strong

sebto’s picture

"Entity View Modes" is great! I found it very helpful to add new view modes for Drupal entities.
Also I wrote a post in my blogto introduce this module for Persian Drupal developers.

Marko B’s picture

"Search result: This is used when presenting search results on the website."

This statement is wrong, actually this doesn't work like that.

judapriest’s picture

Thanks for noticing.

I have add some précision.

doublejosh’s picture

Looking for a way to return view mode settings for a given bundle. Both of these functions are useless for this task...

  • field_bundle_settings()
  • field_view_mode_settings()
  • entity_get_info()
nevets’s picture

Entity view modes only apply when viewing an entity.

memcinto’s picture

After you add a "Search index" mode to a content type, and change fields previously hidden to be displayed in this mode, do you need to re-index the site, or will the newly revealed fields be picked up by the indexing process?

judapriest’s picture

Newly created content will be indexed with the new field. And old content won't be indexed with the new field.

You need to rebuild your whole index if you add or hide the field from the view mode.

memcinto’s picture

Thank you, that's just what I wanted to know.