view

By ldmqmUhAQvn2dL…, 15 October, 2012

This is a small Drupal 7 tip if you wanted to create a custom node view and force a node template to use this custom node view.

Use case

Let's say you are creating a custom node template for a node of type "grades". You may need to show/hide specific fields in your content type for your Grades template. (This is just an example but you can use this tip in various ways).

The Steps

    You can create a new view mode by putting this code into your custom module:

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