I have a custom entity with several fields. Now I would like to group the fields and give each group it's own twig template so that I would be able to compose a page (my custom entity) containing several sections (field groups).

How would you do that? Do I group the fields in the entity preprocess function and give each group it's own '#theme', do I have to change my hook_theme or should the grouping already happen in the controller? Or maybe create a computed field to store the other fields?

Thank you in advance!

1 Answer 1


The field group module is designed to solve this exact problem The Drupal 8 version is reasonably up-to-date.

Fieldgroup will, as the name implies, group fields together. All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.


  • 1
    Thank you, this would probably work, but I would really like to be able to code this myself and just need a hint how to do it the "right" way in Drupal 8. Still appreciate your help!
    – alexej_d
    Commented Jan 26, 2015 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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