所以,这就是我所做的:
创建一个类来处理RenderRendering
管道流程:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore.Diagnostics;
using Sitecore.Caching;
using Sitecore.Mvc.Extensions;
using Sitecore.Mvc.Presentation;
using Sitecore.Sites;
namespace MyNamespace.Pipelines.Response.RenderRendering
{
public class ReplacePathProcessor : Sitecore.Mvc.Pipelines.Response.RenderRendering.RenderRenderingProcessor
{
public override void Process(Sitecore.Mvc.Pipelines.Response.RenderRendering.RenderRenderingArgs args)
{
var viewRenderer = args.Rendering.Renderer as ViewRenderer;
if (viewRenderer != null && viewRenderer.ViewPath.StartsWith("%Theme%"))
{
// Get the current site
var site = Sitecore.Context.Site;
// Get the master database
var database = Sitecore.Data.Database.GetDatabase("master");
// Get the root item
var rootItem = database.GetItem(site.RootPath);
// replace the path
viewRenderer.ViewPath = viewRenderer.ViewPath.Replace("%Theme%", rootItem["Theme"]);
}
}
}
}
添加配置包括
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<mvc.renderRendering>
<processor type="MyNamespace.Pipelines.Response.RenderRendering.ReplacePathProcessor, __Code">
<patch:attribute name="type">MyNamespace.Pipelines.Response.RenderRendering.ReplacePathProcessor, __Code</patch:attribute>
</processor>
</mvc.renderRendering>
</pipelines>
</sitecore>
</configuration>
更改MvcSettings.RenderersViewFolder
为:
<setting name="Mvc.RenderersViewFolder" value="/Themes" />
更改ViewPath
我所有视图的字段以使用以下格式:
%Theme%/Views/{ViewName}.cshtml
希望对某人有所帮助。