5

I have a view containing an unformatted list of fields. I want to create a specific template for the view. I have turned on Twig debug, but it suggests 'views_view_unformatted' for the file name, which would apply to all unformatted lists, but I want it specific to this view. What should be file name be?

2
  • Enable twig debugging by copying default.services.yml to services.yml and following instructions in the twig.config section. The debugging comments will display template file name hints in HTML comments in the page output.
    – cilefen
    Jan 29, 2016 at 23:25
  • 2
    As I say in my post, I have already turned on debug and the suggested file names are not helpful.
    – James
    Feb 1, 2016 at 6:31

4 Answers 4

5

I think the issue here is that Twig debug does not suggest all possible names.

Names containing the view display id or type are possible, but don't seem to be suggested by Twig debug.

The following are the possible template names sorted by precedence:

[base template name]--[view machine name]--[view display id].html.twig
[base template name]--[view machine name]--[view display type].html.twig
[base template name]--[view display type].html.twig
[base template name]--[view machine name].html.twig
[base template name].html.twig
1

To create template for view use following naming convention :

views-view-fileds--views-name--page/block.html.twig

Use page if you are creating template for page view and block for block view

Hope this helps :)

1

I searched for a while till I finally found the solution in the Drupal API:

https://api.drupal.org/api/drupal/core%21modules%21views%21views.theme.inc/group/views_templates/8.2.x

So the correct filename for your case would be:

views-view-unformatted--[view machine name]--[display].html

Like for example:

views-view-unformatted--frontpage--page.html
0

to be more precised with underscore and comma

  • get the view machine name and display name from url

/admin/structure/views/view/event_related/edit/page_1

  • then the template name would be
views-view-fields--event_related--page-1.html.twig
  • for all display of type page for that view:

views-view-fields--event_related--page.html.twig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.