Enable Orchard to support multiple Layout and Orchard

Source: Internet
Author: User

Enable Orchard to support multiple Layout and Orchard

By default, Orchard has only one Layout. Sometimes, multiple master pages are required for our site. To enable Orchard to support multiple Layout, the following is a solution.

I. Create LayoutFilter

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard;
using Orchard.Mvc.Filters;

namespace MyTheme.Filters
{
    public class LayoutFilter : FilterProvider, IResultFilter
    {
        private readonly IWorkContextAccessor _wca;

        public LayoutFilter(IWorkContextAccessor wca)
        {
            _wca = wca;
        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            WorkContext workContext = _wca.GetContext();

            if (HttpContext.Current.Request.Url.PathAndQuery.IndexOf("xxx", StringComparison.OrdinalIgnoreCase) > -1)
            {
                workContext.Layout.Metadata.Alternates.Add("Layout__empty");
            }
        }

        public void OnResultExecuted(ResultExecutedContext filterContext) { }
    }

}

The above implementation code is when our URL address, there are xxx these three characters, let our page call Layout-empty.cshtml this master page.

Ii. Go to the View of the template to create the corresponding Layout page.

Now, for the code above, go to the View folder of our own template to create the Layout-empty.cshtml master page. Note: if we do not create this master page, or Orchard cannot find this master page, Orchard will still find its own default master page to show us the page.

Scan, follow the most courses, and obtain daily exercises

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.