Creating alternates on lists

Topics: Customizing Orchard, General
Dec 23, 2014 at 10:23 AM
Hi

I am trying to work out how to make an alternate on a list, for example List-ProjectionWidget.cshtml.

I have read a fair few examples relating to BlogPosts, but as these are on the BlogPost part the alternate used tends to be the Parts.Blogs.RecentBlogPosts.cshtml or Parts.Blogs.BlogPost.List.cshtml

The example I am working from is a custom content type and as such it has no part to create a list alternate for.

I am struggling finding any examples of how I need to render the model out in the alternate I am interested in and shape tracing is giving no clues as it says the template is coming from source.

Any help would be much appreciated!

Andy
Dec 23, 2014 at 12:32 PM
Hi

You can use IShapeTableProvider. for example
public class DocumentPartShapeProvider : IShapeTableProvider
{
    public void Discover(ShapeTableBuilder builder)
    {

        builder.Describe("Parts_Contents_Publish_SummaryAdmin").OnDisplaying(displaying =>
        {
            var docPart = ((ContentItem)displaying.Shape.ContentItem).As<DocumentPart>();
            if (null != docPart)
            {
                displaying.ShapeMetadata.OnDisplaying(display =>
                {
                    display.ShapeMetadata.Alternates.Insert(1, "GWtec_DocManager_Publish_SummaryAdmin");
                });
            }
        });
...
Dec 26, 2014 at 12:52 AM
Hi @ezrachen

Thanks for you reply, sorry for daft question but I'm quite new to orchard and so am not entirely sure how I would use this in the context of altering a List-ProjectionWidget alternate for my custom content type "Course"?

Where is this code based placed in the solution and how is it best called?

How would you use this in the List-ProjectionWidget alternate to render the list differently, e.g. add a class to the UL etc?

Also you pass in a shapetablebuilder parameter, how is this built in reference to the model in the List-ProjectionWidget?

Finally in the line:
display.ShapeMetadata.Alternates.Insert(1, "GWtec_DocManager_Publish_SummaryAdmin");
Is the 1 just the position to insert the item and the "GWtec_DocManager_Publish_SummaryAdmin" just the alternate you wish to make?

Sorry for the questions, I'm just trying to better understand how to use it.

Many thanks

Andy