DeepFiction.Mvc.Theming

Enables implementing themes for ASP.NET MVC


Keywords
asp.net, mvc, theming, multi, theme
License
GPL-2.0
Install
Install-Package DeepFiction.Mvc.Theming -Version 0.1.0

Documentation

AspNet.Mvc.Theming

Enables implementing themes for ASP.NET MVC.

Build status

To install AspNet.Mvc.Theming,

Install-Package AspNet.Mvc.Theming

Area theme customization not implemented yet!

How to use;

Create Themes (or what you want) folder and put your themes to folder and initialize ThemeManager to use this folder to apply theme and set default theme;

 public class MvcApplication : System.Web.HttpApplication {
        protected void Application_Start() {

           //Omitted for brevity..

            ThemeManager.Instance.Configure(config => {
                config.ThemeDirectory = "~/Themes";
                config.DefaultTheme = "Other";
            });
        }
    }

Put Theme attribute to your controller to use theme you want.

 [Theme("Default")]
    public class WorkController : Controller
    {

        [HttpGet]
        public ActionResult Index()
        {
            return View(new WorkModel
            {
                Content = "Hello World!"
            });
        }

    }

Custom theme resolver

To implement your custom theme resolver see

Sample: SessionThemeResolver

   public class SessionThemeResover : IThemeResolver
    {
        public string Resolve(ControllerContext controllerContext, string theme)
        {
            string result;

            if (controllerContext.HttpContext.Session != null && controllerContext.HttpContext.Session["Theme"] != null)
            {
                result = controllerContext.HttpContext.Session["Theme"].ToString();
            }
            else
            {
                result = (!string.IsNullOrEmpty(theme) ? theme : "Default");
            }

            return result;
        }
    }

init

 ThemeManager.Instance.Configure(config =>
 {
    config.ThemeDirectory = "~/Themes";
    config.DefaultTheme = "Default";
    config.ThemeResolver = new SessionThemeResover();
 });

Save theme to sesion

 Session["Theme"] = "YourTheme";