Skip to content

Instantly share code, notes, and snippets.

@morad7
Created December 5, 2015 09:11
Show Gist options
  • Save morad7/0b1a7d89a3741af29199 to your computer and use it in GitHub Desktop.
Save morad7/0b1a7d89a3741af29199 to your computer and use it in GitHub Desktop.
Drupal custom view mode
/**
* Implements hook_entity_info_alter().
*/
function MYMODULE_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['another_teaser'] = array(
'label' => t('Another teaser'),
'custom settings' => TRUE,
);
}
/**
* Implements hook_preprocess_node().
*/
function MYMODULE_preprocess_node(&$vars) {
if($vars['view_mode'] == 'another_teaser') {
$vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__another_teaser';
}
}
// Duplicate standard node.tpl.php for the content type you need, like node--article--another-teaser.tpl.php. (NOTE: use underscores in template suggestions, dashes in the filename).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment