Creating Alternates for projection part items

Topics: Customizing Orchard
Apr 15 at 1:05 AM
I've created a custom projection layout to display items as a carousel. Logic works great but it displays the carousel items the way they would appear in a summary list. My hope was to be able to create an alternate (Content_ContentType_LayoutType) for when content items are displayed in a carousel or any other projection layout. I'm creating an alternate factory to add to the ShapeMetadata.Alternates collection.
My problem is that I can't figure out how to determine that the parent shape is a projection part and thus get it's layout type.

With shape tracing I was able to see the following shape tree:

The following is what I have so far for the alternate factory:
        public override void Displaying(ShapeDisplayingContext context)
            context.ShapeMetadata.OnDisplaying(displayedContext =>
                // look for ContentItem property
                ContentItem contentItem = displayedContext.Shape.ContentItem;

                // if not, check for ContentPart 
                if (contentItem == null)
                    ContentPart contentPart = displayedContext.Shape.ContentPart;
                    if (contentPart != null)
                        contentItem = contentPart.ContentItem;

                if (contentItem != null)
                    //If Parent Shape ContentPart == "ProjectionPart

                    var shapeName = displayedContext.ShapeMetadata.Type;
                    var contentTypeName = contentItem.ContentType;
                    //var layoutType = Parent Shape/ContentPart/LayoutRecord/Type

                    // Add alternate for projection layout:
                    // [ShapeName]-[ContentTypeName]-[LayoutType].cshtml: (e.g. "Parts.Common.Body-RecentBlogPosts-myLayoutType.cshtml")
                    //displayedContext.ShapeMetadata.Alternates.Add(shapeName + "__" + contentTypeName + "__" + layoutType);