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?
-
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.– cilefenJan 29, 2016 at 23:25
-
2As I say in my post, I have already turned on debug and the suggested file names are not helpful.– JamesFeb 1, 2016 at 6:31
4 Answers
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
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 :)
I searched for a while till I finally found the solution in the Drupal API:
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
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