This project is read-only.

Sharing a part between many widgets

Topics: Customizing Orchard, General
May 12, 2011 at 6:43 PM
Edited May 12, 2011 at 6:44 PM

Let's say I have a Product part define like so: 

public class ProductPart
  public string Description {get;set;}
  public string Name {get;set;}
  public string Price {get;set;}
  public string Picture {get;set;}

And, I want to create 4 different widgets that each display only a single property of the part (ProductDescriptionWidget, ProductNameWidget, ProductPriceWidget, etc)
How do I create only one ProductPartDriver that retrieves the product and passes only the necessary information to each widget? If I set the Model on each widget to ProductPart and just use the property I want (ProductPart.Name on the ProductNameWidget for example), Do I only need to worry about creating a widget in the Migrations file and then creating a unique view for it?
May 12, 2011 at 6:47 PM

Your driver can emit 4 differently named shapes (using CombinedResult). Then you can use Placement to match the content type of each widget and display just the shape you want for that widget. Some of the inbuilt drivers do this to make shapes for different display types (RoutePartDriver does I think).

May 12, 2011 at 6:55 PM

I see. Thank you kind sir, I do believe that's what I need.