How to theme Field Group with Twig

Created on 31 March 2021, about 4 years ago
Updated 20 January 2025, 3 months ago

Can someone help me find the correct filename to use to customise the theming of a field group?

I'm trying to have two fields on a node type, an image and a text field, so that the text field can form the alt text for the image. If I override the theming of just the image field, I cannot access the text field at that point. So I need to theme them as a pair, so I'm using field groups in order to theme them together.

Let's say I've created a field group that is just a regular fieldset named "My Fieldgroup". The machine name I was given is group_my_fieldgroup. I can add an ID and some extra CSS classes, and they come out in the final HTML - so I know I'm looking at right bit of the page.

If I turn on Twig debug, the only hint it gives is that it's using fieldset.html.twig from my base theme. Other elements on the page have comments added suggesting other Twig filenames for more specific theming, but this one does not.

So I guess with trial and error.

I've tried creating various files in the templates folder of my active theme, such as field-group-html-element--group_my_fieldgroup.html.twig, but I can't get it to pick it up.

What twig filenames should I be using for theming a fieldset field group?

💬 Support request
Status

Active

Version

3.0

Component

Miscellaneous

Created by

🇬🇧United Kingdom JamesOakley Kent, UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024