Render a field_group programmatically

Public

If we have a field_group defined in the field display section, this is how one can render them.

Get raw version
php
  1. // This may be weird but we Do need to render the whole entity.
  2. // In this example I use profile2 entity.
  3. $prerendered_profile2 = entity_view('profile2', array($profile2_viewed), 'full');
  4.  
  5. // Now we want to run our pre-rendered entity through field_group pre-rendering function (we skip all others).
  6. $prerendered_profile2_w_groups = field_group_build_pre_render($prerendered_profile2['profile2'][$profile2_viewed->pid]);
  7.  
  8. // Now we have a key with a ready-to-be-rendered group.
  9. $output = render($prerendered_profile2_w_groups['group_stats']);