我正在使用 Orchard 1.9.3 并设置了几个自定义 ContentTypes,它们通过 Autoroute 和 Layout Part 等模拟标准页面类型。
这些类型的页面永远不应该设置为主页,所以我只想隐藏Set as home page
Autoroute 部分的字段,但只隐藏我的自定义类型。我不确定最有效的方法是什么。我可以在展示位置文件中专门定位此字段吗?
我正在使用 Orchard 1.9.3 并设置了几个自定义 ContentTypes,它们通过 Autoroute 和 Layout Part 等模拟标准页面类型。
这些类型的页面永远不应该设置为主页,所以我只想隐藏Set as home page
Autoroute 部分的字段,但只隐藏我的自定义类型。我不确定最有效的方法是什么。我可以在展示位置文件中专门定位此字段吗?
您可以覆盖Parts.Autoroute.Edit.cshtml并包含一些自定义逻辑:
@{
var canSetAsHomePage = true;
var myTypesToDisableHomePageFor = ["MyCustomContentType", "AnotherCustomContentType"];
if (myTypesToDisableHomePageFor.Contains(Model.ContentType)) {
canSetAsHomePage = false;
}
}
// ..
@if (!Model.IsHomePage && canSetAsHomePage) {
if (AuthorizedFor(Permissions.SetHomePage)) {
// ..
为此,您还必须添加一个额外的属性Orchard.Autoroute.ViewModels.AutoroutePartEditViewModel
:
public class AutoroutePartEditViewModel {
...
public string ContentType { get; set; }
}
并确保在以下Editor
方法中设置它Orchard.Autoroute.Drivers.AutoroutePartDriver
:
var viewModel = new AutoroutePartEditViewModel {
CurrentUrl = part.DisplayAlias,
Settings = settings,
ContentType = part.ContentItem.ContentType
};