List / Container Display Possible bug...

Topics: Customizing Orchard, General, Troubleshooting, Writing modules
Mar 21, 2011 at 2:14 PM
Edited Mar 21, 2011 at 2:15 PM


I have found that i'm unable to get lists to display other parts or fields attached to the contenttype i.e. on a page that is a list the "Title" does not show when it has a Route part.

I have managed to fix the issue with the code modification below, as you can see the controller for lists only builds the Display for the list items.

Looking at the code for lists/Containers... I have added the code in RED



        public ActionResult Display(string path, PagerParameters pagerParameters) {
            var matchedPath = _containersPathConstraint.FindPath(path);
            if (string.IsNullOrEmpty(matchedPath)) {
                throw new ApplicationException("404 - should not have passed path constraint");

            var hits = _contentManager
                .Query<RoutePart, RoutePartRecord>(VersionOptions.Published)
                .Where(r => r.Path == matchedPath)
                .Slice(0, 2);

            if (hits.Count() == 0) {
                throw new ApplicationException("404 - should not have passed path constraint");

            if (hits.Count() != 1) {
                throw new ApplicationException("Ambiguous content");

            var container = _contentManager.Get(hits.Single().Id);
            IContentQuery<ContentItem> query = _contentManager
                .Join<CommonPartRecord>().Where(cr => cr.Container.Id == container.Id);

            var descendingOrder = container.As<ContainerPart>().Record.OrderByDirection == (int) OrderByDirection.Descending;
            query = query.OrderBy(container.As<ContainerPart>().Record.OrderByProperty, descendingOrder);

            Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
            pager.PageSize = pagerParameters.PageSize != null && container.As<ContainerPart>().Record.Paginated
                               ? pager.PageSize
                               : container.As<ContainerPart>().Record.PageSize;
            var pagerShape = Shape.Pager(pager).TotalItemCount(query.Count());

            var startIndex = container.As<ContainerPart>().Record.Paginated ? pager.GetStartIndex() : 0;
            var pageOfItems = query.Slice(startIndex, pager.PageSize).ToList();

            dynamic model = _contentManager.BuildDisplay(container);

            var list = Shape.List();
            list.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary")));

            dynamic viewModel = Shape.ViewModel()

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return View((object)viewModel);




@if (Model.ShowPager) {

Is this the desired way for lists to work or is this a bug?

Mar 21, 2011 at 4:00 PM

Thanks. Could you submit this as a patch, please?

Mar 22, 2011 at 10:28 AM


I hope i have done it correctly. I didn't know where to find the "Contributions Branch" as listed in the dococumentation so i just branched of the main branch. Created a related work item as well

Mar 22, 2011 at 7:11 PM

That's weird. Where did you look for it? (probably no big deal for that patch but for next time I'd like to get you set-up for the right branch).

Mar 22, 2011 at 10:43 PM

I have had another look. I've never used Mercurial before, I've spent most of my time with TFS and SVN.

I couldn't find it as I was looking for the option to create the fork off the contributions branch.

I hope I have this right now...

When a fork is created it branches from default. Then using the TortoiseHg Workbench, update to the most recent check-in in the "contributions" branch. Make the fix/patch and check back into "contributions"

Sound right?

Mar 22, 2011 at 11:02 PM


Mar 24, 2011 at 7:03 PM
Edited Mar 24, 2011 at 7:03 PM

Thanks for your contribution, it does seem like an oversight in how Lists render. Likely it just was not tought of that the List itself would be extended with other parts (speculation).

However, there's a few reasons why we aren't going to take this change at the moment.

It will introduce the Lists title in detail view and you won’t be able to turn it off. Even though this is probably what it should have done in the first place, existing sites may have gotten used to it and won’t like the title suddenly showing up. We don't want to impact users in a 1.1 upgrade too much.

Also, the Lists parts will show up always in front of the contents – parts will not be able to extend the content below the list, for example. Ideally we’d introduce some templates with a placement file to make it more manageable, but this is out of scope for 1.1 at the moment.

As a workaround you could continue to use the code change in your own Orchard build until we address the problem. 

Mar 25, 2011 at 7:22 PM

This is exactly what I had found as well. I am working around it now by having an ItemController in my own project with the changes to build the display for the container. It is a bit of a complex problem now that people have learned to use the one without the container displayed. Maybe a feature that can be turned on/off would be the right way to go for a while until the old behavior can be phased out, or just leave the feature in forever.