Themed View Engine

Both WebForms and Razor view engines are supported. The themes should be placed in ~/Themes/myTheme directory with the same structure as ~/Views (you can copy the content of the Views directory to your theme directory). Don't forget to update the path for the master pages (in _ViewStart.cshtml). If you're using Areas, the themes should be in ~/Areas/myArea/Themes/myTheme directory.

The theme name should be set in HttpContext.Items. You can set it manually or use the ThemeAttribute to handle it automatically.

You can continue to use the standard Views for no theme support, that is you don't have to modify an existing project if you have and need only one theme.


For the "Default" Theme

The theme should be in
//for simple views

//for area views

In global.asax.cs
             protected void Application_Start()


			ViewEngines.Engines.Clear();//remove other engines
			ViewEngines.Engines.Add(new ThemedRazorViewEngine()); //using Razor view engine with theme support

Theme specific resources (css, js, images etc)
If you want every theme to have its own static resources, just create a directory in the ~/Content/ with the theme's name. You can get the url of a resource using Url.ThemeResource() extension method.

Having "~/Content/Default/Site.css"

  <link href="@Url.ThemeResource("Site.css")" rel="stylesheet" type="text/css" />
Current Theme is @Url.GetCurrentTheme()

For easy setup
The CavemanToolsMvc source contains the Extras directory where you can find the view layout for a "default" theme. Just copy/dragn'drop the "default" directory in the Themes folder. Then you should modify the _ViewStart file to setup the correct path for the Layout page.

Last edited Feb 14, 2011 at 11:22 AM by mike_sapiens, version 5


No comments yet.