1. 8.3.x core/modules/views/views.theme.inc views_templates
  2. 8.0.x core/modules/views/views.theme.inc views_templates
  3. 8.1.x core/modules/views/views.theme.inc views_templates
  4. 8.2.x core/modules/views/views.theme.inc views_templates
  5. 8.4.x core/modules/views/views.theme.inc views_templates

Describes various views templates & overriding options.

All views templates can be overridden with a variety of names, using the view, the display ID of the view, the display type of the view, or some combination thereof.

For each view, there will be a minimum of two templates used. The first is used for all views: views-view.html.twig.

The second template is determined by the style selected for the view. Note that certain aspects of the view can also change which style is used; for example, arguments which provide a summary view might change the style to one of the special summary styles.

The default style for all views is views-view-unformatted.html.twig.

Many styles will then farm out the actual display of each row to a row style; the default row style is views-view-fields.html.twig.

Here is an example of all the templates that will be tried in the following case:

View, named foobar. Style: unformatted. Row style: Fields. Display: Page.

  • views-view--foobar--page.html.twig
  • views-view--page.html.twig
  • views-view--foobar.html.twig
  • views-view.html.twig
  • views-view-unformatted--foobar--page.html.twig
  • views-view-unformatted--page.html.twig
  • views-view-unformatted--foobar.html.twig
  • views-view-unformatted.html.twig
  • views-view-fields--foobar--page.html.twig
  • views-view-fields--page.html.twig
  • views-view-fields--foobar.html.twig
  • views-view-fields.html.twig

Important! When adding a new template to your theme, be sure to flush the theme registry cache!

See also

\Drupal\views\ViewExecutable::buildThemeFunctions()

Parent topics

File

core/modules/views/views.theme.inc, line 1051
Preprocessors and helper functions to make theming easier.

Comments

imanoop’s picture

Views in D8 does not give the option to create the template from theme settings now you need to create it manually take a look to the article - http://redcrackle.com/blog/drupal-8/theme-views-templates

cslevy’s picture

Why was this removed from the views interface?

danbohea’s picture

Yes, why was this removed from the UI? I wouldn't mind as much if Twig debugging suggested something beyond the names of the template files that are *currently* being used but it doesn't. Guess I'll just have to bookmark this page.

mcpuddin’s picture

Is there any way to do a template override within a custom module?

mrweiner’s picture

The naming convention for a field template is views-view-field--{views machine name}--{page or block machine name}--{field name}.html.twig. The original output is stored in {{ output -}}.

If you need to pull the value of another field into this template, you can do so with {{ view.field.{field-name}.original_value }}

Found this info at http://www.maged.me/blog/drupal-8-override-views-field-template-twig

nmacdougall’s picture

exactly what I needed, thank you!