Multiple layouts and adding Zones to the Content shape

Topics: Administration, Customizing Orchard, General, Troubleshooting
Aug 18, 2011 at 8:28 AM

Hi,

Our company are trialing Orchard Project as a possible platform moving forward for work that we do, but we are coming across problems with defining a number of different layouts that can be used across numerous pages. It would be great if a website had only one layout with the same zones but when does that ever happen, come on!

Ok so we looked into the options and I see them as this (please correct me if I'm wrong)

1. We create lots of zones, different zones for the different layouts and have a lot of if else statements in the one layout.

For eg:

@if (Model.Layout1Primary != null || Model.Layout1Secondary != null)
{
    <div id="layout1Primary">
        @if (Model.Layout1Primary != null)
        {
            @Display(Model.Layout1Primary);
        }       
    </div>
   
    <div id="layout1Secondary">
        @if (Model.Layout1Secondary != null)
        {
            @Display(Model.Layout1Secondary);
        }
    </div>
}
else if (Model.Layout2Primary != null || Model.Layout2Secondary != null)
{
    <div id="layout1Secondary">
        @if (Model.Layout2Primary != null)
        {
            @Display(Model.Layout2Primary);
        }       
    </div>
   
    <div id="layout1Secondary">
        @if (Model.Layout2Secondary != null)
        {
            @Display(Model.Layout2Secondary);
        }
    </div>
}
else if (Model.Content != null)
{
    @Display(Model.Content)
}

Would do the job but is messy and means we need a hell of lot of zones.

2. Create a URL alternative layout, e.g. Layout-url-homepage.cshtml, but then we need one for every page with the different layouts, complete waste of time and a maintenance nightmare!

3. I thought this might work but it doesn't seem to. Create a custom content type for each type of page you want, i.e. one for two column, one for three. Then create an alternative for the Model.Content view, e.g. Content-TwoColumnPage.cshtml. We could then define extra Zones in the Content view.

e.g.

<div id="columnOne">
    @Display(Model.Content)
</div>

<div id="columnTwo">
    @if (Model.ColumnTwoContent != null)
    {   
        @Display(Model.ColumnTwoContent)
    }
</div>

However when I added HTML widgets to my zones defined in the Theme.txt and displayed in our alternative Content view, they didn't display. I'm assuming the case is that the Layout only knows about Zones? Or am I referencing the Zone wrong from within the Content view? Can I access the parent object or something similar? (I thought that as everything is a shape then the CMS might be clever enough to know this is a zone and I have defined widgets in my layer for it)

4. I even tried Layout-TwoColumnLayout.cshtml but no alternates don't seem to work in this way for Layouts, sigh.

5. Install the layout selector module. We could do this and I'm currently looking into it, however I don't really want to have to install a module to fight the way the CMS has been built. I would prefer to work and it's capabilities, however I'm thinking that this is the only option for us.

I've seen a lot of blog posts on the same issue and I'm wondering whether the Orchard guys are thinking of adding this functionality out of the box? Am I missing a glaringly obvious easy way of achieving this?

Thanks for any help in advance.

Regards,

Kevin

Coordinator
Aug 18, 2011 at 6:43 PM

Welcome in the nice world of CMS ... You assume we've had this discussion a thousand times internally ;) and even more solutions in mind. Which means there is no ultimate solution to the problem, but a miriad of alternatives. And actually that's what you also demonstrate with your different solutions, because every user has different needs or differents ideas on how it would be good to do it. And right now Orchard doesn't "push" for any specific solution, it just states that each request is associated with a Layout, and we made Layouts highly flexible.

The good things with this approach are first that we don't assume what the solution might be, and ultimately that if you don't want to bother with Layout selection, the zones folding mechanism can be pretty straightforward. And this opens all possibilities, which is the goal of Orchard. So when you say "I would prefer to work and it's capabilities" then let me tell you "whatever you do, you are" because Orchard is meant to be cutomized for your needs, either you use public modules, or create your custom ones. And sometimes we created some of them, had to make decisions, because otherwise no one would have used it. But you will see in the near future more and more currently "core" modules going in the wild, because we don't want to decide for you what is best for you, so we don't want to let you think we know what is best for you by adding such modules into the core distributed binaries. Wew want to see more Recipes in the Setup with predefined sets of modules, getting downloaded and installed dynamically.

I think what you need is something like the Layout Selector module. But maybe not exactly this one. I hope Pete is also reading this dicsussion, because I think it would be much simpler for users to have a Layout Selector where you can define the layouts in the Theme's manifest, or by just going through every Layout-*.* file, and let you choose from a drop box, without having to create any class. And if this is what you really need Kevin, then make it, we can help youm share it, and create a Recipe which would download and enable this module whenever you create a new Orchard website.

Sebastien

Aug 18, 2011 at 8:31 PM
fevster wrote:

I've seen a lot of blog posts on the same issue and I'm wondering whether the Orchard guys are thinking of adding this functionality out of the box? Am I missing a glaringly obvious easy way of achieving this?

Could you point to some of the interesting ones you found?

We're also investigating how to best work with Orchard in our multiple layout pages web app and we're not that certain how to go about it to be efficient.

Aug 19, 2011 at 2:13 PM

Sebastien had a great answer, and I would just like to reinforce the part about your " I don't really want to have to install a module to fight the way the CMS has been built" comment. I don't know about other CMS systems, but with Orchard modules are the whole point. You're NOT fighting with the way Orchard has been built if you install a module. Orchard itself is mostly made up of modules. The core framework is fairly small. When you install Orchard with the default recipe, most of the functionality is coming from modules which just happen to come with the download. They're not any different than the modules you might write yourself or that you might download from the gallery.

So I would just say, if the layout selector module fits your needs, then use it. That's the way it's meant to work. :-)