I only want to add a class to the inside the fieldset from fieldset.html.twig. It's a bit overkill to extend the template for just to add a class.

How can I achieve this with a preprocess function?

function mytheme_preprocess_fieldset(&$variables) {
// $variables['children']['attributes']['class'][] = 'mb-4';
  • Did you check the content of $variables['children']? It might be already rendered, in which case you are too late and need to find the preprocess hook of the template containing the div which was rendered earlier. – 4k4 Jun 5 '20 at 14:40

Under a fieldsets 'Advanced' settings tab, you can add custom attributes to the fieldset.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.