I want to use hook_preprocess_views_view in order for several views to share the same template, by adding theme_hook_suggestions as described in this article: http://greenash.net.au/thoughts/2014/04/sharing-templates-between-multiple-drupal-views/

function mytheme_preprocess_views_view(&$vars) {

  if (in_array(
    $vars['view']->name, array(
      'whatever'))) {
    $vars['theme_hook_suggestions'][] =

Problem is, I need to specify which display of the particular view it should apply to, rather than the whole view itself. I've tried printing the $vars out which results in a huge recurring array which doesn't seem to include the display name anywhere.

I'm also aware you do this via tagging in the views UI. The same problem occurs though - I can't add a tag to a particular display of a view.

If there is another way I can accomplish this I'm all ears!

1 Answer 1


You can get the display ID through the current_display property of the View object, e.g.

$view = $vars['view'];
if ($view->name == 'foo' && $view->current_display == 'bar') {
  // ...
  • Oh shhh... how did I not see that? Thanks!
    – Chris
    Jun 11, 2015 at 8:50
  • 2
    Heh heh, I must have used this over a hundred times and I still go looking for display_name or display_id every time...
    – Clive
    Jun 11, 2015 at 8:58
  • Now I have the problem that it's not picking up my template, but that's another question...
    – Chris
    Jun 11, 2015 at 9:07
  • 6
    in drupal 8 you would use $view->id() instead op the property name Oct 6, 2017 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.