0

有谁知道是否可以使用 url 替代模板覆盖 ContentType 的 DisplayType 模板?例如,是否可以用 Content-url-homepage-Page.Detail.cshtml 覆盖模板:Content-Page.Detail.cshtml?玩了一会儿,好像不是这样。有谁知道我想要实现的目标是否可行?

谢谢!

4

1 回答 1

0

您可以通过启用“形状跟踪”功能并查看替代列表来查看形状的所有可用替代,例如http://devhammer.net/blog/Customize-Orchard-CMS-with-Designer-Tools

例如,在主页的主要内容项上,我开箱即用:

~/Themes/MyTheme/Views/Content.cshtml
~/Themes/MyTheme/Views/Content-url-homepage.cshtml
~/Themes/MyTheme/Views/Content.Detail.cshtml
~/Themes/MyTheme/Views/Content-Page.cshtml
~/Themes/MyTheme/Views/Content-10.cshtml
~/Themes/MyTheme/Views/Content-Page.Detail.cshtml
~/Themes/MyTheme/Views/Content-10.Detail.cshtml

您的选择是添加或扩展现有的替代工厂,例如 Orchard.DesignerTools.Services.UrlAlternatesFactory 例如

// appends [ShapeType]__url__[Url]_[DisplayType] alternates
context.ShapeMetadata.Alternates = _urlAlternates.Value.Select(url => 
    context.ShapeMetadata.Type + "__url__" + url + "_" + 
        context.ShapeMetadata.DisplayType)
        .Union(context.ShapeMetadata.Alternates)
        .ToList();

这将为您提供备用 ~/Themes/MyTheme/Views/Content-url-homepage.Detail.cshtml

或使用现有的替代品之一,例如

~/Themes/MyTheme/Views/Content-10.Detail.cshtml

看起来它可能适合您的目的(对我来说,使用 id 不如使用 url 干净)

我还尝试调整“Url Alternates”功能的功能优先级,以便将 url 替代项附加到所有其他现有替代项,因为它从代码中显示出来是预期的,但据我所知,这不起作用或不是支持的。

于 2013-01-14T00:14:07.797 回答