Projections - Customization?

Topics: Customizing Orchard, General
Nov 25, 2013 at 6:46 PM
I'm having some difficulty customizing the Projection I've built for a custom Content Part I've created. I have a course catalog, made up o CourseDefinitionParts/PartRecords. I've created a Query, and a Shape that returns the following (from CourseDefinitionPartDriver):
protected override DriverResult Display(CourseDefinitionPart part, string displayType, dynamic shapeHelper) {
    return ContentShape("Parts_CourseDefinition", () => 
                shapeHelper.Parts_CourseDefinition(
                    Title: part.CourseName,
                    Description: part.CourseDetails,
                    Tuition: part.Tuition,
                    ReviewerTuition: part.ReviewerTuition,
                    DiscountTuition: part.DiscountTuition,
                    NumberOfDays: part.NumberOfDays,
                    IsActive: part.IsActive
                ).Where(part.IsActive == true)
            );
}
As you can see, I'm trying to return a ContentShape only when part.IsActive == true (yes, I know the '==true' is redundant), but the shape is returned regardless. That's one thing I'd like to fix, but I'm not seeing how.

The second is that I'm getting a bullet point in the list for each item. I'd like to remove that. I'ver read through a couple of Bertrand's blog posts on the subject of custom formatting of Queries (like this: http://weblogs.asp.net/bleroy/archive/2011/05/23/orchard-list-customization-first-item-template.aspx), but I'm not seeing how to apply it to what I'm doing. I may be blind to the solution, but it's not jumping out at me.

The third is related--I'd like to present an accordion summary of one of the fields. It contains HTML data, and I'd like to have a "see more" link at the bottom of that field that goes to a page that displays the full content.

Finally--and this is just weird--at the bottom of the page that displays the Projection, there is a final empty bullet point, with a '1' in the content area. I have absolutely no clue where this is coming from. Any ideas?

Can anyone point me in the right direction for the custom formatting? Am I missing something in Bertrand's posts, or should I be looking elsewhere?

Thanks.
Dec 4, 2013 at 1:25 AM
Has anyone looked at this question at all? I've figured out the bullet points, but I can't figure out how to restrict what comes back (IsActive) or how to remove the '1' at the bottom.

Help, please.
Dec 4, 2013 at 2:57 AM
Edited Dec 4, 2013 at 2:59 AM
I thought I sent a response to this, but it stayed in the draft mail, here it is:

1 You can check using an if statement to return only when part.IsActive is true, else null. shapeHelper creates a dynamic object, I think that's why it does not complain about Where. Something like this:
return ContentShape("Parts_CourseDefinition", () => 
            { if (part.IsActive == true) 
                 return shapeHelper.Parts_CourseDefinition(
                    Title: part.CourseName,
                    Description: part.CourseDetails,
                    Tuition: part.Tuition,
                    ReviewerTuition: part.ReviewerTuition,
                    DiscountTuition: part.DiscountTuition,
                    NumberOfDays: part.NumberOfDays,
                    IsActive: part.IsActive
                ); 
            else return null;
            }
 );
This does not feel right, by the way. What if you want to display inactive courses? You need to find another way to filter out inactive courses by other means I think. I am not even sure if it will complain about returning null shape, which you will need to handle in the view template by the way.

A better way would use a boolean field instead of IsActive member of the part, which will be available in the query filters, and return the shape unconditionally.

If it's not sutiable for your needs, you can implement a filter provider and query against IsActive. It's quite complicated, but you can find examples in the code, one in Orchard.Comments.Projection.CommentsFilter.

2 You can set a CSS class for the projection, and use it to set list-style-type to none.

3 You probably need to use one of the accordion plugins for jQuery, and create alternate views to render whatever necessary to display as you want. For summary, you can use Summary display type (a setting of the projection) and return a summary shape from the driver. You can see an example in Orchard.Core.Common.Drivers.BodyPartDriver, how it returns a Combined result for detail and summary, and check respective views in Orchard.Core.Common.Views for differences between Parts.Common.Body.cshtml and Parts.Common.Body.Summary.cshtml

4 You can inspect the html source of the page to find out if it comes from the driver (see if it has the same article/div structure as the others in the list), or somewhere else. If you turn shape tracing on, you can find out about the content item of its origin, if it comes from one.