在果园CMS使用替代品Document.cshtml [英] Using Alternatives for Document.cshtml in Orchard CMS

查看:172
本文介绍了在果园CMS使用替代品Document.cshtml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的网站上,需要以覆盖document.cshtml文件,以便根据用户的当前位置我能将一个特定的CSS级的能力。

I am currently working on a website that requires the ability to overwrite the document.cshtml file so that I can apply a specific CSS-class based on the user's current location.

我试图使用URL替代品,如:

I have attempted to use URL alternatives such as:

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

不过似乎所有的人都用Document.cshtml,而不是使用一个基于URL。我可以很容易理解,这是预期的目的,但我不知道是否有可能实现上面的功能。

however it appears that all of them use the Document.cshtml as opposed to using one based on the URL. I could easily understand that this is the intended purpose, however I was wondering if it would be possible to implement the functionality above.

我认为,我可能已经在这一领域取得了一些进展,而不是使用URL方案,并简单地对模型添加一个字段(文档),简单地拉动该网站目前的区域并应用类的身体。

I believe that I may have made some progress in this area, as opposed to using URL alternatives, and simply adding a field on the Model (for the document) to simply pull the current "Area" of the site and apply that class to the body.

(在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>

我认为,这可能比一个previously提出一个简单的解决方案。不过,我想知道究竟是什么把,我可以从文档的模式访问一个领域的最简单的方法,就可以。

I believe that this may be an easier solution than the one previously suggested. However, I am wondering what the easiest method of actually placing a field that I could access from the Model of the Document, would be.

推荐答案

Document.cshtml是一个包装的布局形状。包装器不支持候补委员。更换document.cshtml模板选择的唯一方法是删除从包装收集现有包装上的布局形态的元数据,并添加自己的。

Document.cshtml is a wrapper for the Layout shape. Wrappers don't support alternates. The only way to replace the document.cshtml template selectively is to remove the existing wrapper from the wrappers collection on the metadata of the layout shape and add your own.

别急......我想不出任何好的理由,为什么你会想这样做。是什么在document.cshtml是样板HTML,应该是整个网站一样。在您的更新描述的解决方案是要走的路。

But wait... I can't think of any good reason why you'd want to do that. What's in document.cshtml is boilerplate HTML that should be the same across the site. The solution described in your update is the way to go.

这篇关于在果园CMS使用替代品Document.cshtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆