1

Is it possible to have different template files for different display modes of the same entity without using template_preprocess_page()? If not, how can I get all the available display modes for a certain entity type so I can create some sort of automatic template suggestion?

Eg: For a node I have by default the 'Full' and 'Teaser' display types. I can add more display types using Display suite module or by creating a custom module. I need to create multiple template files like node--content-type--teaser.tpl.php to keep everything clean and not use lots of IF statements.

Thanks :)

1 Answer 1

7

I'll go with this solution after all:

function MYMODULE_preprocess_node(&$vars) {
  $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
}
4
  • Honestly that's the quickest and I think best way to go. I've been doing that for a bunch of different sites and I can't think of a reason not to do it this way. May 14, 2012 at 16:49
  • 1
    To then override use a name like: node--article--teaser.tpl.php Aug 5, 2013 at 21:18
  • Just to add, I had to flush the cache twice in order to get this Oct 2, 2013 at 13:49
  • Note that the Entity Views Mode module adds this for you.
    – Brian
    Oct 14, 2013 at 20:46

Your Answer

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

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