Score:1

How can I add a CSS class to a #type table render element?

br flag

I was trying to add a custom classname to the table in my custom module. But for some reason it's not working (Drupal 9). I can not get the table class name added into the HTML. Any help would be appreciated.

Edit: I was following this post below, but no luck. Add a class to a Drupal table cell containing ['data']

    '#type' => 'table',
    '#attributes' => [
       'class' => ['table-class-name'],
     ],
    '#header' =>  [], /header column goes here/
    '#rows' => [], / data goes here/ 
  ];
Jaypan avatar
de flag
That should work - maybe you need to clear your cache.
Jahid avatar
br flag
Thanks @Jaypan for your time, i have tried to clear cache several times, but i still don't see the table class name in HTML. However, I have added a class to the <th> of the same table that worked okay. So strange...
cn flag
Have you tried adding the class to the table template?
I sit in a Tesla and translated this thread with Ai:

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.