Create themable field group 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!
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.
  
  https://www.drupal.org/project/field_group