在 Orchard CMS 的 ASP.NET 中,页面标题在什么时候获得默认初始值?

At what point is the page's title get default initial value in ASP .NET with Orchard CMS?

我下载了一个完整的ASP。 NET MVC 应用程序,但是当我尝试更改 Razor 视图中的页面标题时,我得到 默认值 + MyNewTitle.

我尝试更改以下页面的标题:

Layout.Title = "_test";
Model.Title = "_test";

但是我得到了:SiteName - _test

这是Layout.cshtml

的开头
@functions {
    // To support the layout classifaction below. Implementing as a razor function because we can, could otherwise be a Func<string[], string, string> in the code block following.

    string CalcuClassify(string[] zoneNames, string classNamePrefix)
    {
        var zoneCounter = 0;
        var zoneNumsFilled = string.Join("", zoneNames.Select(zoneName => { ++zoneCounter; return Model[zoneName] != null ? zoneCounter.ToString() : ""; }).ToArray());
        return HasText(zoneNumsFilled) ? classNamePrefix + zoneNumsFilled : "";
    }
}
    @{
    //Layout.Title = "test";
    //Model.Title = "TEST";

    /* Global includes for the theme
    ***************************************************************/
    Script.Require("jQuery").AtHead();
    Style.Include("site.css");
    Style.Include("styles.css");
    Script.Require("jQuery");
    Script.Include("scripts.js");

    RegisterLink(new Orchard.UI.Resources.LinkEntry
    {
        Rel = "stylesheet",
        Type = "text/css",
        Href = "http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic&subset=latin,cyrillic-ext,greek-ext,greek,latin-ext,cyrillic"
    });

    RegisterLink(new Orchard.UI.Resources.LinkEntry
    {
        Rel = "stylesheet",
        Type = "text/css",
        Href = "http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic"
    });

    /* Some useful shortcuts or settings
    ***************************************************************/

    Func<dynamic, dynamic> Zone = x => Display(x); // Zone as an alias for Display to help make it obvious when we're displaying zones

    /* Layout classification based on filled zones
    ***************************************************************/

    //Add classes to the wrapper div to toggle aside widget zones on and off
    var asideClass = CalcuClassify(new[] { "AsideFirst", "AsideSecond" }, "aside-"); // for aside-1, aside-2 or aside-12 if any of the aside zones are filled
    if (HasText(asideClass))
    {
        Model.Classes.Add(asideClass);
    }

    //Add classes to the wrapper div to toggle tripel widget zones on and off
    var tripelClass = CalcuClassify(new[] { "TripelFirst", "TripelSecond", "TripelThird" }, "tripel-"); // for tripel-1, triple-2, etc. if any of the tripel zones are filled
    if (HasText(tripelClass))
    {
        Model.Classes.Add(tripelClass);
    }

    //Add classes to the wrapper div to toggle quad widget zones on and off
    var footerQuadClass = CalcuClassify(new[] { "FooterQuadFirst", "FooterQuadSecond", "FooterQuadThird", "FooterQuadFourth" }, "split-"); // for quad-1, quad-2, etc. if any of the quad zones are filled
    if (HasText(footerQuadClass))
    {
        Model.Classes.Add(footerQuadClass);
    }

    /* Inserting some ad hoc shapes
    ***************************************************************/

    WorkContext.Layout.Header.Add(New.Branding(), "5"); // Site name and link to the home page
    WorkContext.Layout.Footer.Add(New.BadgeOfHonor(), "5"); // Powered by Orchard
    //WorkContext.Layout.Footer.Add(New.User(), "10"); // Login and dashboard links

    /* Last bit of code to prep the layout wrapper
    ***************************************************************/

    Model.Id = "layout-wrapper";
    var tag = Tag(Model, "div"); // using Tag so the layout div gets the classes, id and other attributes added to the Model
}
@tag.StartElement

它不在 Layout.cshtml 中,而是在 Document.cshtml 中。在那里你会找到顶部的某个地方:

<!DOCTYPE html>
<html lang="@WorkContext.CurrentCulture">

<head>
    <meta charset="utf-8" />
    <meta name="robots" content="index, follow, archive" />

    <!-- See the construction of the title here -->
    <title>@Html.Title(title, siteName)</title>

    // other stuff
</head>

可以在 Orchard 中找到此文件。Core/Shapes/Views/Document.cshtml

您可能不想在本文档中更改它,因为那样您将更改核心文件(这是一种不好的做法,例如,如果您更新 Orchard,该文件将被再次覆盖)。

幸运的是,Orchard 是一个了不起的 CMS,它允许您自定义所有内容,而无需更改核心。

我建议,如果你还没有这样做,创建一个新的主题,基于 TheThemeMachine 主题,将 Document.cshtml 复制到它的 views 目录,并在其中进行你想要的更改。

Here 您可以找到如何创建自定义主题