Rendering nested lists

Topics: Customizing Orchard, Troubleshooting
Apr 15, 2011 at 5:09 AM
Edited Apr 15, 2011 at 5:09 AM


I have a problem with a site I've been working on - I have a list containing 4 Packages (custom type). The Package type has a Container part, and contains a number of PackageItems (another custom type).

I can successfully render the list and display a summary of the 4 packages - What I want to do is also display the details of the package items underneath each summary. I've tried a few ideas, but none have been successful.

Example of what I'm trying to render when viewing the list:

  • List of Packages (Url = "/packages")
    • Package 1 (Summary)
      • Package Item 1
      • Package Item 2
    • Package 2 (Summary)
      • Package 2 Item 1
      • Package 2 Item 2
    • Package 3 (Summary)
      • Package 3 Item 1
      • Package 3 Item 2

Can this be done without a custom module?



Apr 15, 2011 at 8:39 AM

To build a template of a child content item you'd need to call Services.ContentManager.BuildDisplay(item,"Summary").

I don't actually know if it's possible to call this directly from a view (will be experimenting with this later) - but all the existing examples show this being called either from a driver or a shape event/provider, and the results passed into the model (which would therefore require custom code / module).

I've been successfully rendering multiple levels of hierarchy using that method, it's definitely possible.

Apr 16, 2011 at 2:52 AM

Thanks - that worked perfectly - I can call it from the view without any problems.

It does feel wrong though, I think I'll have to create a custom module to get around that annoying feeling of mixing concerns, but this will do for now :)

Apr 16, 2011 at 3:29 AM

I'm just wondering, from the view, how did you get a reference to ContentManager? I was looking earlier and couldn't find it. (I have a specific case where I'd like to be able to customise the DisplayType from a template override)

But yes you probably want to do it from a driver or something else in the shape building pipeline if you want to avoid too much code in the view.

Apr 16, 2011 at 5:13 AM

To get the content manager, I used this code:

var cm = WorkContext.Resolve<IContentManager>();

Apr 16, 2011 at 11:37 AM

Ah I see - awesome, thanks! Didn't realise WorkContext resolved dependencies...