Drupal Views and Twig templates
Unlike most of Drupal's templates, Views do not provide a file name suggestion for overriding Twig templates. So how do we know exactly what to name our template? View templates can be created in a variety of ways, but the easiest way to remember this is by following this rule:
[base template name]--[view machine name].html.twig
So in the case of our Categories view, will want to create a new Twig template with the name views-view-unformatted--categories.html.twig
.
Begin by navigating to the core/modules/view/templates
folder and following these remaining steps:
- Copy
views-view-unformatted.html.twig
and place it into ourtheme/octo/templates
folder. - Rename
views-view-unformatted.html.twig
toviews-view-unformatted--categories.html.twig ...
Get Drupal 8 Theming with Twig now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.