Problem/Motivation

When you add a views template override, duplicates of the same override appear and show as selected in twig debug, but the view no longer displays any output.

Steps to reproduce

<!-- FILE NAME SUGGESTIONS:
   ▪️ views-view--news--all.html.twig
   ▪️ views-view--news.html.twig
   ✅ views-view.html.twig
-->

Create the file views-views--news--all.html.twig, using the same content as views-view.html.twig, and now you see:

<!-- FILE NAME SUGGESTIONS:
   ✅ views-view--news--all.html.twig
   ▪️ views-view--news.html.twig
   ✅ views-view--news--all.html.twig
   ▪️ views-view--news.html.twig
   ✅ views-view--news--all.html.twig
   ▪️ views-view.html.twig
-->

Additional info

In my case I'm using Drupal CMS with radix and my own subtheme.
The same problem exists if I copy the views-view--news--all.html.twig file into my Radix Starter Kit template directory.
I'm using the pre-created "News" view with three displays "All News", "Latest News", and "Related News".

This code probably creates the theme suggestions - from the top of the radix views.theme file:

/**
 * @file
 * Theme and preprocess functions for views.
 */

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function radix_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
  // Add a suggestion based on the view name and the current display.
  $view = $variables['view'];
  $name = $view->id();
  $display = $view->current_display;
  $suggestions[] = 'views_view__' . $name;
  $suggestions[] = 'views_view__' . $name . '__' . $display;
}

Comments

tstermitz created an issue. See original summary.

tstermitz’s picture

Issue summary: View changes
tstermitz’s picture

Issue summary: View changes
doxigo’s picture

It's been a while since I last looked into this and I don't recall the reason for it Tom, I wonder if it's a core issue but we'll investigate, thanks

  • doxigo committed d111bd6c on 6.0.x
    Issue #3509232 by tstermitz: Remove the views theme suggestion alters...
doxigo’s picture

Status: Active » Fixed

This one took a while Tom, you were right about the cause. Core's ViewExecutable::buildThemeFunctions() already builds the whole list, including views_view__NAME and views_view__NAME__DISPLAY, so ViewHooks was appending entries that were already there. Same for the unformatted one.

The no-output part does not reproduce on 6.0.x. I added a views-view--content--page-1.html.twig override, and it resolves and renders rows normally, so that half looks fixed since 6.0.1. Only the doubled debug list was left.

While in there the exposed form alter was emitting nonsense. It splits the form #id on dashes and reads index 2 as the view id, but the id is views-exposed-form-content-page-1, so index 2 is the word form. Every exposed filter was getting views_exposed_form__form. Core covers this one too.

Removed all three

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.