0

I created a view with a page display whose path is /admin/content/noun, and whose format is table. I'd like to override the table template with views-view-table--the-view-name--the-display-id.html.twig. The view's path means the view is displayed in the admin theme. Where do I put the template?

Creating a Claro's sub-theme doesn't work. Customizing web/core/themes/claro/templates/classy/views/views-view-table.html.twig works, but that's hacking core.

5
  • 3
    Sub-theming is the way to go, to avoid hacking core. Tested drush generate theme for the base theme claro and it installed just fine. You might only need to clean up the block layout.
    – 4uk4
    Mar 23 at 21:23
  • drush generate theme with a base theme of claro creates a almost blank file structure from Claro in my themes directory. Enabling "claro_custom" one time is enough to show me that this is not a direction we would want to go in. I updated hook_theme_registry_alter() from drupal.stackexchange.com/questions/1249/…, but now the table from the view display contains no values, only my customizations which are outside the table. Still trying to get hook_theme() to work.
    – esod
    Mar 24 at 15:15
  • After you enabled the theme and set it as default backend theme you may need to adjust the blocks, like re-placing them the same way they were in original Claro. The sub-theme is empty, yes, because all the parent files live in original Claro and you now in your sub-theme add only those again you want to customize. (Overriding the template from a custom module is easier IMHO.)
    – leymannx
    Mar 24 at 20:28
  • I definitely prefer to override the template from a custom module. But what's the base hook for a views template override? I can't tell from views_theme().
    – esod
    Mar 25 at 15:22
  • 1
    The 'base hook' is 'views_view_table'. Here's the code. /** * Implements hook_theme(). */ function mymodule_theme($existing, $type, $theme, $path) { return [ 'views_view_table__my_view__my_admin_table' => [ 'base hook' => 'views_view_table', ], ]; }
    – esod
    Mar 25 at 16:58

0

Browse other questions tagged or ask your own question.