I have a DW10 project where we would like to display fields from FIeld Display Groups in the order that the are ordered there. We would like to display the for a products variants that in this case is a product family. The fields in the Product Display Groups are of type "Property".
I have poked around in the API to try to achieve this. So if I have a ProductViewModel with the master product, what would be the best way to achieve this?
To display fields from Field Display Groups in order (as configured in the backend) for a product and its variants (product family), you can use the FieldGroupViewModel from the ProductViewModel.
public List<FieldValueViewModel> Fields { get; set; }
Each display group contains the fields in that group, and you get them in the order defined in the group setup, assuming the frontend respects that order.
Recommended Approach
Here’s how you can access and render the field display groups and their fields in the correct order for a product or product family (master/variant):
1. Use ProductViewModel.DisplayGroups
Assuming you have a ProductViewModel for your master product:
@foreach (var fieldGroup in Model.DisplayGroups) { <div class="field-group"> <h3>@fieldGroup.Name</h3> @foreach (var field in fieldGroup.Fields) { <div class="field"> <strong>@field.Name:</strong> @field.Value </div> } </div> }
This will:
Loop through all Field Display Groups
Respect their order
Render each field in the order defined in the backend group configuration
To Show Fields for Each Variant
If you're displaying all variants under a product family, and want to show display group fields for each:
@foreach (var variant in Model.Variants) { <h2>@variant.Name</h2> @foreach (var fieldGroup in variant.DisplayGroups) { <div class="field-group"> <h4>@fieldGroup.Name</h4> @foreach (var field in fieldGroup.Fields) { <div class="field"> <strong>@field.Name:</strong> @field.Value </div> } </div> } }
This assumes that the variant products also include their DisplayGroups – which they should, if the model is set up with full product data (e.g., via a standard product detail page or PIM).
Notes
Order is preserved as long as you're using Model.DisplayGroups directly.
Only fields included in the relevant Field Display Group setup will appear.
Display groups can include standard fields, custom fields, and category attributes.