在Orchard CMS中使用Document.cshtml的替代品

Rio*_*ams 3 .net c# orchardcms razor

我目前正在开发一个网站,需要能够覆盖document.cshtml文件,以便我可以根据用户的当前位置应用特定的CSS类.

我试图使用URL替代方案,例如:

  • Document.cshtml
  • 文档的URL,AreaA.cshtml
  • 文档的URL,AreaB.cshtml
  • Document.url-AreaC.cshtml

但是看起来所有人都使用Document.cshtml而不是使用基于URL的文件.我很容易理解这是预期的目的,但是我想知道是否可以实现上述功能.


更新

我相信我可能在这方面取得了一些进展,而不是使用URL替代方案,只需在模型上添加一个字段(用于文档),只需拉出网站的当前"区域"并将该类应用于身体.

(在document.cshtml中)

@using Orchard.Mvc.Html;
@using Orchard.UI.Resources;
@{
    RegisterLink(new LinkEntry {Type = "image/x-icon", ...});

    string title = Convert.ToString(Model.Title);
    string siteName = Convert.ToString(WorkContext.CurrentSite.SiteName);

     //Pull the Area here
    string area = Model.DesignatedAreaField;
}
<!DOCTYPE html> 
<html lang="en" class="static @Html.ClassForPage()"> 
<head> 
    <meta charset="utf-8" />
    <title>@Html.Title(title, siteName)</title> 
    @Display(Model.Head)
</head> 
<body class='@area'>
//Body goes here
@Display(Model.Body)
@Display(Model.Tail)
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我相信这可能比以前建议的解决方案更容易.但是,我想知道实际放置一个我可以从文档模型中访问的字段的最简单方法是什么.

Ber*_*Roy 7

Document.cshtml是Layout形状的包装器.包装不支持替代品.有选择地替换document.cshtml模板的唯一方法是从布局形状的元数据上的包装器集合中删除现有的包装器并添加自己的包装器.

但是等等......我想不出你为什么要这么做的任何理由.document.cshtml中的内容是样板HTML,在整个站点中应该是相同的.您的更新中描述的解决方案是要走的路.