Skip to main content
  • Guides & Documentation

Knowledgebase

Featured articles, how-to guides and quick tips.

Theming Individual Views Fields in Drupal 8

It's a common theming development requirement you may encounter — theming a specific field (or fields) via templates.

Of course, it's possible to theme directly via the Views module in Drupal, utilizing either the Rewriting fields or Wrapper HTML.

But these features provide limited functionality.

You may have further attributes and markup that Drupal won't natively allow in the Views administration interface, and in this case it's probably best to do it directly with a template file.

There's a very specific (and lengthy) naming convention that should be used here.

This is particularly the case if you're trying to target a specific field, but only for a particular View, or a particular View display (i.e. Block 1, Block 2, Page 1, Page 2, etc).

You don't want to be theming every single occurrence of the field, in general, since you could inadvertently theme the field where it exists elsewhere.

Here's a good drilled-down naming convention to use:

views-view-field--[machine name of view]--[machine name of view display, e.g. page-1}--[machine name of the field].html.twig

Of course, replace the bold text with the appropriate values.

This should get you well on your way to theming specific fields, for the right Views and View displays.

Include this file in the /templates directory of your Drupal theme, and don't forget to clear all Drupal caches after creating and modifying the file.