When it comes to providing custom view modes for entities in Drupal, most developers turn immediately to Display Suite or Entity View Modes. Display Suite is very powerful, but I've found it to be far too "heavy" for most of my use cases. In this case, by "heavy" I mean that the module does way more than I need it to. It does a lot of things I simply don't want on my site. Entity view modes is a lighter-weight approach to supplying additional view modes, but I found that even it was cumbersome when it came to managing my view mode configuration in an easily-deployable way.
I wanted a simpler solution, and I knew it couldn't be that hard to provide this functionality in a custom, streamlined module.
The code snippets below do the following:
- Define new display modes. As you'll see, this is super easy to do in code.
- Suggest node templates based on the view mode of the given node. e.g. a teaser template vs. a full display template.
- Suggest page templates based on the node type being viewed. e.g. alter the page markup for Article nodes.