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 :)

7

I'll go with this solution after all:

function MYMODULE_preprocess_node(&$vars) {
  $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
}
  • 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. – Lester Peabody May 14 '12 at 16:49
  • 1
    To then override use a name like: node--article--teaser.tpl.php – Joshua Stewardson Aug 5 '13 at 21:18
  • Just to add, I had to flush the cache twice in order to get this – O V Oct 2 '13 at 13:49
  • Note that the Entity Views Mode module adds this for you. – Brian Oct 14 '13 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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