Created
March 11, 2017 04:56
-
-
Save barryokane/71c0f64cbbf2c7c14336c0051224ce17 to your computer and use it in GitHub Desktop.
Inspired by Heather Floyd's article (http://24days.in/umbraco-cms/2016/unique-sites-using-theming), however our use case is slightly different: we want to share a library of partials between multiple Umbraco sites with custom overrides on specific sites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using Umbraco.Web.Mvc; | |
namespace Endzone.Umbraco.PatternLib | |
{ | |
public class PatternLibRazorViewEngine : RenderViewEngine | |
{ | |
public PatternLibRazorViewEngine() : base() | |
{ | |
/* | |
* Default partials "patterns" folder, these can be overridden simply by placing a partial with the same name in "Views/Partials" | |
*/ | |
const string patternLibViewFolder = "~/Views/_patterns"; | |
/* | |
* Let Umbraco's RenderViewEngine do the work, just add our partials view location to the list... | |
*/ | |
var umbracoPartialViewlocations = PartialViewLocationFormats.ToList(); | |
var patternLibPartialViewLocations = umbracoPartialViewlocations.Select(x => x.Replace("~/Views", patternLibViewFolder) ).ToArray(); | |
umbracoPartialViewlocations.AddRange(patternLibPartialViewLocations); | |
PartialViewLocationFormats = umbracoPartialViewlocations.ToArray(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
using Umbraco.Core; | |
using Umbraco.Web.Mvc; | |
namespace Endzone.Umbraco.PatternLib | |
{ | |
/// <summary> | |
/// Registers site specific Umbraco application event handlers | |
/// </summary> | |
public class UmbracoEvents : ApplicationEventHandler | |
{ | |
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
base.ApplicationStarting(umbracoApplication, applicationContext); | |
/* | |
* Replace the Umbraco RenderViewEngine with our PatternLibRazorViewEngine | |
* this allows us to add our own View locations without too many extra steps | |
*/ | |
IViewEngine remove = null; | |
ViewEngines.Engines.ForEach(x => { | |
if (x.GetType() == typeof(RenderViewEngine)) | |
remove = x; | |
}); | |
if (remove != null) | |
ViewEngines.Engines.Remove(remove); | |
ViewEngines.Engines.Add(new PatternLibRazorViewEngine()); | |
} | |
} | |
} |
@smdooley : not verbatum. We have a similar concept in a base project. Are you looking for a solution to this?
@smdooley : not verbatum. We have a similar concept in a base project. Are you looking for a solution to this?
I have used http://24days.in/umbraco-cms/2016/unique-sites-using-theming for a few projects but I have experienced the occasional issue with third-party App_Plugins and routing, so I am interested to see/hear other approaches.
Is your approach compatible with the Grid Layout and Umbraco Forms?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Barry
Have you managed to use this approach on any live projects?