Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293450

Drupal Theme Hook suggestions WTF

$
0
0

In a recent project I discovered a major WTF in the theme hook suggestions. Perhaps someone could clarify this.

I needed to distiguish between views block and views page and added the following hook:

/**
* Implements hook_theme_suggestions_HOOK_alter() for node templates.
*/
function MY_THEME_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
  $view = $variables['view'];
  $suggestions[] = 'views__' . $view->getDisplay()->getBaseId();
}

This ends up in the following suggestions:

<!-- FILE NAME SUGGESTIONS:
   * views--block.html.twig
   x views-view.html.twig
-->

I added the template called views--block.html.twig but the template does not get discovered.
The theme system still uses views-view.html.twig.

Now the WTF:

If i rename the file from views--block.html.twig to views-view--block.html.twig there are new suggestions added without changing the preprocess function:

<!-- FILE NAME SUGGESTIONS:
   x views-view--block.html.twig
   * views--block.html.twig
   x views-view--block.html.twig
   * views-view.html.twig
-->

And now it works. For me this is not understandable, could someone explain this to me ?


Viewing all articles
Browse latest Browse all 293450

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>