Custom ContentPart - Sorting and displaying properties in projections

Topics: Administration, Customizing Orchard, Writing modules
Mar 16, 2015 at 5:15 PM

I've created a simple ContentType (EngiProfileType) which is composed by a custom ContentPart (EngiProfilePart). My custom part is in turn composed by properties (mostly strings and a few datetime types). Everything works as I'm perfectly able to create said content types, save, edit and displaying them correctly.

Now, what I'd love to achieve (and getting mad while trying to do so) is to display a list of EngiProfileTypes, sorted by different criterias (pre-defined in the admin ui, atm I don't need to let users do their sorting).

Since I'm already showing them using Orchard.Projections I thought, why don't I use the IPropertyProvider interface? It'd be cool as my module would then interact with other modules, achieving the ultimate integration that Orchard allows compared to other CMSes.

But here's the problems:
  1. I need to create a EngiProfilePartProperties : IPropertyProvider class. I've added Projections dependency to my module.txt and my .csproj . This seems to be the only thing I've done correctly
  2. I then implemented the interface:
public void Describe(DescribePropertyContext describe)
    describe.For("EngiProfileType", T("EngiProfileType"), T("EngiProfile's properties"))
        .Element("Name", T("Name"), T("Engineer's name"),
            ctx => Display(ctx, MyProperties.Name),
            (ctx, ci) => Render(ctx, ci, MyProperties.Name))
        .Element("Surname", T("Surname"), T("Engineer's surname"),
            ctx => Display(ctx, MyProperties.Surname),
            (ctx, ci) => Render(ctx, ci, MyProperties.Surname));
But is it correct? EngiProfilePart as you can easily immagine represents an Engineer's base data (Name, Surname being just some of them).

Display and Render are implemented as follow:
public enum MyProperties
    Name, Surname

public dynamic Render(PropertyContext context, ContentItem contentItem, MyProperties property)
    //TODO -- IMPLEMENT ME! return _contentManager.GetItemMetadata(contentItem).DisplayText;

public LocalizedString Display(PropertyContext context, MyProperties property)
    switch (property)
        case MyProperties.Name:
            return T("EngiProfile: Name");
        case MyProperties.Surname:
            return T("EngiProfile: Surname");
            return T("EngiProfile: unknown");
I can't figure out how to correctly implement this interface! There is no documentation available and Projections project doesn't help much.