0

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 2

0

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.

-1

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

parameters:
  twig.config:
    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.

2
  • 3
    Turning on Twig debug is a good idea in general, but it doesn't add debug suggestions for Views in Drupal 8. Also, you shouldn't modify the default file; you should use a local services.yml so that you don't accidentally turn on twig debugging in production. Aug 28, 2020 at 14:10
  • 1
    This is a recurring DX/TX frustration drupal.org/project/drupal/issues/2656694#comment-10796174
    – 4uk4
    Aug 28, 2020 at 19:22

Your Answer

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

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