Add views theme suggestions

Created on 23 October 2024, 6 months ago

Problem/Motivation

It would be beneficial to have view suggestions supported out of the box.

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function THEME_HOOK_theme_suggestions_views_view_alter(
  array &$suggestions,
  array $variables
): void {
  $view = $variables['view'];

  if (
    $view instanceof ViewExecutable
    && $display = $view->current_display
  ) {
    $view_id = $view->id();
    $original = $variables['theme_hook_original'];

    $suggestions[] = "{$original}__$view_id";
    $suggestions[] = "{$original}__{$view_id}__$display";
  }
}
✨ Feature request
Status

Active

Version

5.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States droath

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024