Developer forum

Forum » Dynamicweb 10 » Variants and FieldDisplayGroups

Variants and FieldDisplayGroups

Aki Ruuskanen
Aki Ruuskanen
Reply

Hi,

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? 

Regards / Aki 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Aki

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.

From Documentation

Per the Field Display Groups documentation:

"Field display groups are added to the product view model and can be shown in frontend if implemented."

Also, the FieldGroupViewModel API reference confirms that:


 
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.

 
Aki Ruuskanen
Aki Ruuskanen
Reply

Thanks Nicolai. 

Problem is that the ProductViewModel does not have a "DisplyGroups". It has a "FieldDisplayGroups", but that does not have "Fields" list. 

The ProductViewModel is retrieved the "Swift2" way:

    ProductViewModel product = null;
    if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
    {
        product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
    }

 

Regards / Aki

   
Aki Ruuskanen
Aki Ruuskanen
Reply

OK, I was poking around there also, but I'll check it out. Thanks. 

/Aki 

 

You must be logged in to post in the forum