Problem/Motivation
The current implementation of theme_table() will always render {th} elements in the {thead} header row of a table. This while {td} elements are allowed in a header row and can have a valid use, e.g. an empty first cell if the other cells in the first column contain headers for the rows.
Proposed resolution
theme_table allows to specify that a cell in the body of the table is rendered as a{th} by using the "header" attribute. This same attribute can be used to override the default rendering of {th} in header rows:
$row[] =array('data' => ' ', 'header' => FALSE)
This should make the theme render a {td} instead of a {th}. Currently the actual value of the header entry is ignored. The mere presence of this key is used as "I want a header".
Remaining tasks
- Write patch.
- Use the actual value of the "header" entry also in the body rendering of theme_table().
User interface changes
N.A.
API changes
Backwards compatible, assuming that people never have written code like
$row[] =array('data' => ' ', 'header' => FALSE)
to get a {th} in the header... Which will be very unlikely and a "bad coding practice that should be punished".
Though it still should be documented of course in the theme_table documentation.
Comments
Comment #0.0
fietserwinUpdated issue summary.
Comment #1
lauriiiComment #2
joelpittetYou can create a template suggestion for
table.html.twigand change the markup to whatever you prefer.table--other-thead-tags.html.twigComment #3
fietserwinIt is fixed, but not because of the way as described in #2, that would better be described as won't fix, but because it is in core\modules\system\templates\table.html.twig:
and some other table twig files, but not e.g. in core\modules\views\templates\views-view-table.html.twig.
Comment #4
joelpittet@fietserwin ah thanks forgot that I worked on that... #1939008: Convert theme_table() to Twig
It would be nice to consolidate the views table template but that may not be entirely possible, worth a look though.
You can do either way to resolve this. I'd recommend writing your tags in the templates though instead of tying the tags to some strange structure in a render array.
Comment #6
xjm