Score:0

How to target a specific table with Twig on a specific page?

cn flag

I have a table I would like customize in CSS but first need to target it with Twig. The problem I am running into is that the twig template is global so it is for ALL tables. If I edit this table with this twig template, it will change all the tables on all the pages.

views-view-table.html.twig

In the Twig Documentation, I see no mention of any Table ID's so how do I target this specific table for this page?

enter image description here

The main table in the center of the page is targeted and edited with this twig template:

views-view-grouping.html.twig

I want to make the side table look similar but there rendered on 2 different twig templates and I only want to change it for THIS page only and not every table on the rest of the site.

Kevin avatar
in flag
You need to add template suggestions to get more specific template ids for this view style
pmichelazzo avatar
in flag
You need a theme suggestion and this answer here helps you: https://drupal.stackexchange.com/questions/227709/adding-theme-suggestions-programmatically-for-views-rows-fields
beltouche avatar
cn flag
See also https://www.drupal.org/docs/theming-drupal/twig-in-drupal/twig-template-naming-conventions#s-views
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.