Architectural Blog, Modern Buildings & Casino Designs Loading...

Using custom template files for different view modes

You can use custom template files for different view modes really easily in Drupal 7 by adding this to your theme’s template.php file:

function THEMENAME_preprocess_node(&$vars) {  // Custom display templates will be called node--[type]--[viewmode].tpl.php   $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode']; }

You can then make your own copy on node.tpl.php and rename it node–[type]–[viewmode].tpl.php and it will only apply to the content type [type] when it is displayed in the view mode [viewmode] for example node–article–teaser.tpl.php.

Well there you have it, simple stuff really. Of course for larger sites you might want to avoid template files as much as you can and consider going for a more in-depth solution like Display Suite or Panels but for smaller sites this will do the trick just fine.