I am using Drupal 8, and I created a new view mode for the News page content type, in the custom display settings section.
How can I create a template file for this view mode?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
According to the D8 docs, you'd need to create a file in your your custom theme with this naming convention:
So if I had a content type of
person and a view mode of
Teaser my template name would be
node--person--teaser.html.twig. Be sure to follow the machine name patterns if you're using spaces in your custom view mode.
Generally speaking, I like to put it in a
templates/node directory of my theme so that other devs can find it quickly. Whether you copy the base node template (
core/modules/node/templates/node.html.twig) or start from scratch is up to you.
Also, if you turn on theme debugging, Drupal will output in HTML comments a list of template name suggestions, starting from most specific to least specific filenames.