View theme override in drupal 8

1.8k views Asked by At

I am new to drupal 8 and i need to override a views template. So, for that I have enabled theme debug in services.yml to view the twig template suggestion name.

This is my view theme debug.

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_unformatted__test_content_view' -->
<!-- FILE NAME SUGGESTIONS:
   x views-view-unformatted--test-content-view.html.twig
   x views-view-unformatted--test-content-view.html.twig
   * views-view-unformatted.html.twig
-->

Then, I created the file in templates of drupal8 theme and the theme file calls. I used themename_views_view_unformatted__test_content_view() function to override in themename.theme file but the function doesn't called.

Is there anyway to override the variables coming to the twig template. Can anyone give me suggestion to override the views template.

Thanks in advance.

1

There are 1 answers

1
Alma On

The template name is views-view-unformatted.html.twig, to override the variables in this template implement the preprocess hook for that template in your themename.theme file. E.g.

function themename_preprocess_views_view_unformatted(&$variables) {
  // Implement logic here to override the variables.
}