Hide zones in Orchard CMS

463 Views Asked by At

I am looking for a way to hide certain zones on 1 particular page in Orchard CMS, I am using version 1.6.1.

Some background to my issue - every page on the site has a header and footer as defined in the Layout.cshtml file. For 1 page on the site I want to hide the header and footer which is made up of 6 zones. In MVC I would add another layout file and use nested layouts but I know this can't be done in Orchard.

I have a solution that does the job, however I am not keen on it as it involves putting code in the Layout.cshtml file, my solution is as follows

if (Request.Url.PathAndQuery.Contains("register-1"))
{
    Model.Header1 = null;
    Model.Header2 = null;
    Model.Header3 = null;
    Model.Header4 = null;
    Model.Footer1 = null;
    Model.Footer2 = null;
}

This is coupled with doing a null check before outputting the zone like so

@if (Model.Header1 != null)
{
    <div id="layout-banner">
        @Zone(Model.Header1)
    </div>
}

Is there a way to do this without having to put code in the Layout.cshtml file? Or perhaps there is a better approach all together?

2

There are 2 best solutions below

0
Bertrand Le Roy On BEST ANSWER

Use a layer to hide the widgets, that uses a not url("~/register-1") to exclude the page. The widgets that are placed in this layer will not appear on your register-1 page.

3
Alexander  Petryakov On

You can create layout alternate for pages. If it is only one page that url alternate will be suitable.

  1. Copy your Layout.cshtml (from current theme folder)
  2. Rename one to Layout-url-your-page-url.cshtml
  3. Also you should activate Url Alternates Module

For more defails view http://docs.orchardproject.net/Documentation/Alternates