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());
}
}
}
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();
}
}
}