1

I have added twig suggestion from .theme file to views__view.html.twig for customizing taxonomy.

   function mediumish_blog_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
      if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical' && $tid = \Drupal::routeMatch()->getRawParameter('taxonomy_term')) {
       $term = Term::load($tid);
       $suggestions[] = 'views__view__taxonomy_term';
     }
   }

I am getting suggestion in twig suggestion display but when i am creating file and applying my custom theme, its not actually displaying output of that file, Its still using the default views--view.html.twig.

1

Replace the underscore characters with hyphens, and clear the cache.

The template filename should be views--view--taxonomy--term.html.twig.

   function mediumish_blog_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
      if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical' && $tid = \Drupal::routeMatch()->getRawParameter('taxonomy_term')) {
       $term = Term::load($tid);
       $suggestions[] = 'views__view__taxonomy__term';
     }
   }
|improve this answer|||||
  • Yes, I did that – Ankit Jain Apr 12 '18 at 12:26
  • Sorry, I edited that views--view path, I forget to write in that manner – Ankit Jain Apr 12 '18 at 12:27
  • Check whether the template is in the current theme – Mykola Veriga Apr 12 '18 at 12:36
  • Yes, It is in the current theme, I made it myself – Ankit Jain Apr 12 '18 at 12:40
  • I didn't get you ? – Ankit Jain Apr 12 '18 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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