Active
Project:
Views Bootstrap
Version:
5.5.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
25 Sep 2026 at 10:08 UTC
Updated:
8 Oct 2026 at 08:37 UTC
Jump to comment: Most recent
Grouping a table by a field adds a <caption> element with the field value above each group in the table.
Sadly the configured HTML element and classes are not used within the caption.
See above
Print the field in the caption as it was configured (HTML element, classes, ...) like in the views result (unless 'remove tags' setting is enabled?)
Comments
Comment #2
anybodyComment #4
shelaneComment #6
anybodyThanks for the quick resolution @shelane! Great!
Still I think the second part is not yet solved:
Sorry I think I didn't point that out clear enough.
The expected result (additionally to your fix) is that if you select an HTML element for the field you group by, that HTML element should be used, just like in the output of the field. This is especially helpful to make it a
<h2>or<h3>and add classes.The actual result is that only the plain text of the field is printed in the caption.
Comment #7
shelaneAh, yes, I missed that. I'll take a look shortly.
Comment #9
anybodyThanks - quite some custom code. I would have hoped there's a helper method that can be used to render the field value first, before printing it into the caption?
['#markup']is always risky regarding security, so we should be extra careful.Comment #11
shelaneI just ran my changes through codex and it responded with a few suggested changes and a response on what is available. Note that I looked at what core views does for this and it does use markup.
The grouping field value is already rendered by Views. StylePluginBase::renderGrouping() calls getField(), which returns the sanitized field
output as a MarkupInterface. Core then places that rendered value in the caption.
There is no reusable helper that reapplies the field’s configured wrapper element and classes. That logic normally lives in
preprocessViewsViewFields(), which is not used for grouped table captions. Calling the field renderer again would duplicate rendering and
still would not add the wrapper.
The custom code therefore only recreates the configured wrapper using elementWrapperType() and elementWrapperClasses(). It does not mark raw
field data as safe. html_tag also escapes the tag and attributes.
I agree that extracting ['#markup'] is unnecessarily brittle. We can instead preserve the existing caption render array as a child:
$caption = $vars['caption'];
$vars['caption'] = [
'#type' => 'html_tag',
'#tag' => $wrapper_type,
'#attributes' => [
'class' => explode(' ', $wrapper_classes),
],
'content' => $caption,
];
This keeps Drupal’s existing rendering, escaping, and cacheability handling intact while adding only the configured wrapper.
Comment #12
anybodyThanks @shelane that sounds good!
Comment #13
shelaneComment #15
anybodyHi @shelane just came across this again in a further project and had to think about this part again
(from: https://git.drupalcode.org/project/views_bootstrap/-/commit/bf10829d5331...)
Is there ANY case where you'd want the grouping caption BELOW the table?
For "regular" Drupal users the outcome is still unextected in tables my eyes. Shouldn't we just add
in general to have the expected behaivor also in tables? (Like in all other cases)?
Comment #16
anybody