Ragesh
Ragesh

Reputation: 3063

How do I add zone based alternates for ContainerWidgets in Orchard?

I'd like to be able to customize how lists are rendered by ContainerWidgets. Shape tracing only gives me the following options:

  1. Parts.ContainerWidget.cshtml
  2. Parts.ContainerWidget-url-homepage.cshtml

I'd like to be able to supply an alternate for a specific zone. I think that IShapeTableProvider is the way to go, but I'm just not sure. I've also thought of using a Widget alternate (Widget-MyZone.cshtml) but I can't understand how to get to the underlying list items to render them myself. Also, overriding Widget seems like overkill. Ideally, I'd like to be able to add a Part alternate like Parts.ContainerWidget-MyZone.cshtml.

There seem to be quite a few posts around the web that discuss this problem, but nothing I could find really points to a concrete working example.

Is this the right approach? Something else I should try? Any examples around?

Upvotes: 1

Views: 721

Answers (2)

Ragesh
Ragesh

Reputation: 3063

It turns out that Orchard 1.4 has built-in support for zone based container widget alternates. The recommended solution, therefore, is to just upgrade to 1.4.

Upvotes: 1

Giscard Biamby
Giscard Biamby

Reputation: 4609

IShapeTable provider should work. What happens when you try it? Here's a rough example (not tested):

public class Shapes : IShapeTableProvider {
    public void Discover(ShapeTableBuilder builder) {
        builder.Describe("Content").OnDisplaying(displaying => {

                if (displaying.ShapeMetadata.DisplayType == "Detail"
                    && (displaying.Shape.ContentItem as ContentItem).ContentType.Equals("MyWidgetType", System.StringComparison.OrdinalIgnoreCase)) {

                    var metadata = displaying.ShapeMetadata;
                    ContentItem contentItem = displaying.Shape.ContentItem;
                    metadata.Alternates.Add("MyWidgetType_MyCUstomAlternate");
                }

            });



    }

Upvotes: 0

Related Questions