How do I add a template suggestion for a Views block?

Drupal Answers Asked by wbeasley on October 21, 2020

I am very much so new to Drupal and have moved to this platform after working with Magento for 5 years.
I am trying to create a template for a view. I have created the twig template under /templates/views/ called views-view–partners–partners–sales.html.twig but do not know how to hook the theme into using this twig template.

2 Answers

Inside sites/default/services.yml add config like this:

    debug: true

(and clear the cache) and it will turn on twig debug mode, which will give you information (inside html comments in page source) on what templates are used and possible template name suggestions to override those templates.

Answered by MilanG on October 21, 2020

You need to name your template based on the rules for Views templates.

For example, "views-view--partners--partners--sales.html.twig" would mean:

  • viewid: partners
  • view-display-id: partners
  • fieldid: sales

If this is correct, then all you need to do is clear the cache and reload; the template should be picked up automatically.

Answered by Patrick Kenny on October 21, 2020

Add your own answers!

Related Questions

” a field on Manage display

1  Asked on February 6, 2021 by carrotandme


Display Entity Reference field twice, with different display modes

1  Asked on February 3, 2021 by paul-canning


Media html not rendering in blocks

1  Asked on February 3, 2021 by kristoffer-rom


How can I programmatically change the view mode?

4  Asked on February 3, 2021 by jmzea


How do I avoid API calls are cached?

2  Asked on February 2, 2021 by user1648228


Custom JSON api normalizer is not initiated

0  Asked on February 1, 2021 by kevinvhengst


Suddenly unable to add a field to a new content type

1  Asked on January 31, 2021 by leif


an error when changing the date form

1  Asked on January 30, 2021 by mahdi-alikhasi


Display content based on taxonomy with view

2  Asked on January 30, 2021


Why is my code called again written on build form?

0  Asked on January 29, 2021 by namit-garg


How to change path of taxonomy facet

1  Asked on January 24, 2021 by rahulkumar-it


Form field not show on Ajax Callback even the callback is called

1  Asked on January 23, 2021 by emad-karhely


Features to import content types

2  Asked on January 18, 2021 by webmaster-pf


Redirect user to previous page after registration

2  Asked on January 15, 2021 by lbogdan


field_info_field: how to define the content type name?

1  Asked on January 14, 2021 by bruno-von-paris


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP