Layout not being applied when container is used

Topics: Customizing Orchard
Mar 25, 2011 at 6:52 PM

All,

Having the same problem as neonp in this thread:

http://orchard.codeplex.com/discussions/242150

His issues weren't really addressed, and the answer that was given there really confused me (I'm not a C# Dev...yet...). So here it is again:

I'm using the randomPete's layout module to define several different layouts for chapters.  When I just use the layout, everything works fine.

When I add a container to the chapter, and then add the containable part to the page (in this case a Pretty Gallery), ONLY the Parts/PrettyGallery.cshtml shows up, and NOT the Layout. I then have to go through and zap everything in the database to get the layout to show up again.

If the answer in thread above actually does address this issue, I apologize, but I just didn't get it.

Thanks,

Stu

Mar 25, 2011 at 7:44 PM
Edited Mar 25, 2011 at 7:48 PM

It sounds like you're having a very different problem to neonp; he describes:

> I am trying to have a content type for which both container and containable parts are defined. However, as soon as it contains one element, the template I have defined is not applied anymore on this item. Is there any way to override this behavior ?

So I think he's just saying his item template stops being applied; not the whole layout.

The most likely suspect is unfortunately my module; nothing else should override the layout. It could possibly be a conflict between my module and another. Can you quickly test for me and see if disabling the Layout Selector feature prevents the problem occurring? That at least confirms whether it is or isn't something to do with the module.

Out of curiosity, what layout override names are you using? I'm wondering if you have a Layout-PrettyGallery.cshtml and somehow the Parts/PrettyGallery.cshtml is getting found instead; although I can't think exactly how this would happen!

Edit: Further on that, you said in the other thread that you modified the LayoutSelectorService.cs itself. Can you post your full modified code for that please, so I can see what you altered?

Thanks

Coordinator
Mar 25, 2011 at 7:47 PM

What content type are chapters? Is it something you built? What do you mean by "just use the layout"? What is the relationship between chapters and pages?

Mar 25, 2011 at 8:12 PM

@pete:

For this case, the layout that I have names is Layout-ScreenShots.cshtml.  On this page, I haven't really changed anything from the original ThemeMachine Layout.cshtml, other than to put a DIV at the top telling me THIS IS THE SCREENSHOT TEMPLATE.

I tried disabling/enabling the Layout selector module, and nothing really changed.  It's almost as if the Pretty Gallery module completely overrides anything else I'm doing.  The next test I tried was to disable that module, and I got rid of the containable object off the Chapter.  Still nothing... The only way I can get back to using the Layout Selector is to zap the info in the db and start again...

Here's my code:

namespace Downplay.Orchard.LayoutSelector.Services
{
    public class LayoutSelectorService : ILayoutSelectorService
    {

        private readonly IEnumerable _providers;

        public LayoutSelectorService(IEnumerable providers)
        {
            _providers = providers;
        }

        /*public IEnumerable GetLayouts()
        {
            foreach (var p in _providers)
            {
                foreach (var l in p.GetLayouts())
                {
                    yield return l;
                }
            }
        }*/

        public IEnumerable GetLayouts()
        {
            yield return "Default";
            yield return "Overview";
            yield return "ScreenShots";
            yield return "Videos";
            yield return "Downloads";
            yield return "Comparison";
            yield return "Features";
            yield return "Specifications";
        }

    }  
}

@ Bertrand: Chapters seem to be a regular page as part of the imported module.  If I reference Pete's layout in the Chapter module, I get the layout result, but when I add the PRetty Gallery container into the layout, all I see is the PG.cshtml part.

Chapters are effectively nested pages.

Thanks again guys... Really appreciate the help.

Stu

Mar 25, 2011 at 8:42 PM
Edited Mar 25, 2011 at 8:43 PM

Just out of curiosity... Do I have to put anything into the layout so that a containable object would be rendered?

I'm thinking that since there's no place on the layout right now to render the module, it just defaults back to it's own layout...

Mar 25, 2011 at 10:04 PM
Edited Mar 25, 2011 at 10:06 PM

If you've just copied everything from TheThemeMachine's Layout.cshtml, everything should be in there for displaying any content shapes that get thrown at the page; so that shouldn't be the problem.

I've just done some testing with lists and I'm noticing a problem where the LayoutSelectorPart's driver doesn't actually get called on the list page - only the child items are being rendered. So the layout alternates aren't being activated, your base Layout.cshtml will be used instead. Have you modified that at all? - I'm wondering if you've stripped stuff out of it, so what you're actually seeing is a bare Layout.cshtml with the gallery in the middle. Now, this does make it the same problem described on the thread you referenced - once the container has an item, the container itself's template no longer gets used.

The solution described in that thread certainly isn't very clear, I need to dissect it (I have to work around it for my own purposes anyway...) and I'll try to post clearer instructions once I've done so!

Edit: I might have slightly misunderstood your initial post. When you said "NOT the Layout" I thought you meant that none of the layout bits were showing up at all (i.e. no menu, anything) - but I think what you might have meant is just that your override layout and the container layout weren't showing? Sorry for the confusion!

Coordinator
Mar 26, 2011 at 12:25 AM

You just need a Content zone.