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

fietserwin’s picture

Issue summary: View changes

Updated issue summary.

lauriii’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Postponed
joelpittet’s picture

Status: Postponed » Fixed

You can create a template suggestion for table.html.twig and change the markup to whatever you prefer.

table--other-thead-tags.html.twig

fietserwin’s picture

It 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:

 * ...
 * - header: Table header cells. Each cell contains the following properties:
 *   - tag: The HTML tag name to use; either TH or TD.
 * ...

and some other table twig files, but not e.g. in core\modules\views\templates\views-view-table.html.twig.

joelpittet’s picture

@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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

Category: Feature request » Support request