This project is read-only.

Help with trying to display categorised pages returned by a projection within an accordion

Topics: General
Apr 25, 2013 at 11:51 AM
I have a number of content types (which are pages containing more content types) which need to be displayed within an accordion jquery control. Using custom shapes and a projection I have the vanilla version working as:

Custom Shape
    var buildShapes = Model.BuildShapes;    

<div class="accordion">         
    @foreach (dynamic shape in buildShapes())
Summary shape
<h3 class="ui-accordion-header">
    @(new HtmlString(Model.ContentItem.BodyPart.Text))    
This works really nicely. I now need to produce multiple accordions, each with a title, based upon a category held within the projection query results (the individual query type).

I would prefer to do this within the single projection and have the code which will layout the separate accordions based upon each category. This requires me to loop through each contentitem in the projection using (I loop through the partner list)
    IEnumerable<object> partners = Model.ContentItems;    
What I have been struggling with is drawing the final summary shape, i.e. the content item (partners[x]). The vanilla example uses the very sexy @Display(shape) which handles everything I need to do.

I find I am unable to enumerate the Model.Buildshapes, or pass the contentitem in a way that is similar.

Has anyone a view on how to access the contentitem shape I need to pass to the Display call, or the similar functionality as this, but using the contentitem?
Apr 25, 2013 at 12:35 PM
Essentially, you are looking to render a content item in the same way you render a content item shape, correct?
You can't render a content item directly; instead, use ContentManager.BuildDisplay() which expects an IContent (which ContentItem implements). This method will invoke all the drivers of the parts associated with the content item, yielding a shape tree. This shape is what you render using @Display(). If you want to do this from a view, you need an instance of IContentManager, which you can get via WorkContext.Resolve<IContentManager>(). However, if you can do this from a controller, driver or shape table provider, that would be preferred. One way to do this is having your accordion implemented as an 'ad hoc' shape, for which you implement an IShapeTablePRovider. Within that shape table provider, you would invoke IContentManager.BuildDisplay to build a list of shapes based on the list of content items you want to render, and store that list in the shape as a property. Then, the template rendering that shape will have a list of content item shapes available, which you can render using @Display().
Apr 25, 2013 at 12:58 PM
That rocks!!!

I think I owe you a beer at Harvest. Many thanks.
Apr 25, 2013 at 1:38 PM
Make that a coke and I'm your man :)