Orchard Part Alternates by Content Type

Feb 6, 2011 at 7:19 PM


I have added a IShapeTableProvider  to try to insert an alternate Content template for my Blog Post detail page. So far I have the below working


public class DataShapeProvider : IShapeTableProvider
        private readonly IWorkContextAccessor workContextAccessor;

        public DataShapeProvider(IWorkContextAccessor workContextAccessor)
            this.workContextAccessor = workContextAccessor;

        public void Discover(ShapeTableBuilder builder)
              .OnDisplaying(displaying =>




But the problem is that the alternate applies to all Parts_Common_Body shapes so it's not selective enough (my about me page displays the changes for blog posts which is not what I want). On bertrands post about alternates he uses the content item to work out if the page was the homepage and only then supply an alternate. How do I do the same for Blog Post pages. I tried to access the ContentItem by calling.

 ContentItem contentItem = displaying.Shape.ContentItem;

But this returned null.

How do I work out that I am displaying a Blog Posts Detail page?




Feb 7, 2011 at 10:05 PM

displaying.Shape.ContentPart.ContentItem should work.

Feb 12, 2011 at 12:04 PM

Thanks you are correct. But what I am failing to understand is how you know that (besides the fact you work on the team of course). When writing the statement I get intellisense for displaying.Shape.ContentPart and displaying.Shape.ContentItem. The ContentItem on the shape is null. 

My normal instinct is the use the debugger to explore the object graph (thats how I would normally learn the system) but this just simply doesn't work for me because all the objects are dynamic.... It is very frustrating.

For example breaking on display.Shape the debugger doesn't show the ContentPart or ContentItem properties. Is there a technique for debugging dynamic objects that I am missing?

Feb 13, 2011 at 12:09 AM

I looked at how the shape was getting created in the driver. We are currently working on new debugging tools for shapes. It will get better. In the meantime, digging into the shapes can be done by going into its behaviors. But it's hard.