1

I am using Drupal 8, and I created a new view mode for the News page content type, in the custom display settings section.

enter image description here

How can I create a template file for this view mode?

1
  • Hey Rick what exactly is unclear in template naming suggestions? What have you tried so far? Please help to clarify by expanding your question and providing more details.
    – leymannx
    Commented Aug 20, 2017 at 17:36

1 Answer 1

6

According to the D8 docs, you'd need to create a file in your your custom theme with this naming convention:

node--[type|nodeid]--[viewmode].html.twig

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.

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.